Express res.json() example

Once the server process the client request, the result needs to be sent back to the client. Express provides various methods to send the result…

The post Express res.json() example appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

Once the server process the client request, the result needs to be sent back to the client. Express provides various methods to send the result like res.send(), res.json(), res.redirect(). In today’s post, we are going to see res.json().

res.json() is a utility wrapper around res.send() that also adds the Content-Type: application/json header to the response. This header is used by the frontend to determine the type of the response and parse it accordingly. JSON is widely used as a way to exchange data, so these methods are provided for convenience.

app.get('/client', (req, res) => {
  res.json({
    name: 'John Doe',
    country: 'India'
  });
});

The post Express res.json() example appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-10-19T05:00:28+00:00) Express res.json() example. Retrieved from https://www.scien.cx/2021/10/19/express-res-json-example/

MLA
" » Express res.json() example." Deven | Sciencx - Tuesday October 19, 2021, https://www.scien.cx/2021/10/19/express-res-json-example/
HARVARD
Deven | Sciencx Tuesday October 19, 2021 » Express res.json() example., viewed ,<https://www.scien.cx/2021/10/19/express-res-json-example/>
VANCOUVER
Deven | Sciencx - » Express res.json() example. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/19/express-res-json-example/
CHICAGO
" » Express res.json() example." Deven | Sciencx - Accessed . https://www.scien.cx/2021/10/19/express-res-json-example/
IEEE
" » Express res.json() example." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/10/19/express-res-json-example/. [Accessed: ]
rf:citation
» Express res.json() example | Deven | Sciencx | https://www.scien.cx/2021/10/19/express-res-json-example/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.