![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between res.send and res.json in Express.js
Whenever an Express application server receives an HTTP request, it will provide the developer with an object, commonly referred to as res. For example,
Example
app.get('/test', (req, res) => { // use req and res here })
The res object basically refers to the response that'll be sent out as part of this API call.
The res.send function sets the content type to text/Html which means that the client will now treat it as text. It then returns the response to the client.
The res.json function on the other handsets the content-type header to application/JSON so that the client treats the response string as a valid JSON object. It also then returns the response to the client.
Advertisements