Categories
JavaScript Answers

How to respond with a JSON object in Node.js?

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *