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

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.