Categories
JavaScript Answers

How to send error HTTP response in Express and Node.js?

Spread the love

Sometimes, we want to send error HTTP response in Express and Node.js.

In this article, we’ll look at how to send error HTTP response in Express and Node.js.

How to send error HTTP response in Express and Node.js?

To send error HTTP response in Express and Node.js, we can call the status and send methods.

For instance, we write

response.status(code).send(new Error("description"));

to call status with the status code number and call send with the Error instance with the error text to return a error response in our route handler function.

Conclusion

To send error HTTP response in Express and Node.js, we can call the status and send methods.

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 *