Randomblue Randomblue - 2 years ago 97
Javascript Question

How to programmatically send a 404 response with Express/Node?

I want to simulate a 404 error on my Express/Node server. How can I do that?

Answer Source

Nowadays there's a dedicated status function for this on the response object. Just chain it in somewhere before you call send.

res.status(404)        // HTTP status 404: NotFound
   .send('Not found');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download