且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Express / Node以编程方式发送404响应?

更新时间:2023-08-16 23:05:52

现在有一个专门的 状态功能在响应对象上。

  res.status (404)// HTTP status 404:NotFound 
.send('Not found');


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

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');