终止ExpressJS请求

如何结束快递3的要求? res.end()肯定不会停止处理。

exports.home = function(req, res) { res.end(); console.log('Still going, going...'); 

你需要return 。 例如,

 exports.home = function(req, res) { return res.end(); console.log('I will never run...'); 

res.end()只需完成并刷新对客户端的响应。 但是,就像其他任何动作一样,它并不会告诉JavaScript停止运行,所以我们需要明确地return该函数(尽pipe我可能会问,为什么在刷新响应后为什么会有代码呢?想运行…?)。