Sometimes, we want to respond with a JSON object in Node.js.
In this article, we’ll look at how to respond with a JSON object in Node.js.
How to respond with a JSON object in Node.js?
To respond with a JSON object in Node.js, we call the Express res.json
method.
For instance, we write
res.json({ foo: "bar" });
in a middleware or route handler function to return { foo: "bar" }
as a JSON response.
Conclusion
To respond with a JSON object in Node.js, we call the Express res.json
method.