Difference between res.send() and res.json() in Express.js?
Last Updated :
24 Apr, 2025
In this article, we will learn about res.send() & res.json(), along with discussing the significant distinction that differentiates between res.send() & res.json().
Let us first understand what is res.send() and res.json() in Express.js?
res.send() - The res.send() function is used for sending the response for the HTTP request. It takes a parameter body. The parameter can be a String, Buffer object, an object, Boolean, or an Array.
Syntax:
res.send( [body] )
Parameter: The body parameter takes a single argument that describes the body that is to be sent in the response.
Content Type: The Express sets the content type of the parameter according to the type of the body parameter.
- String & HTML - “text/html”
- Buffer - “application/octet-stream”
- Array & object - "application/json"
Return Type: It is used to send a response to the client and then ends the response process. The method itself doesn't return anything.
Example: This example demonstrate the simple res.send().
JavaScript