Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我将如何结束 Express 3 请求?res.end() 当然不会停止处理。
exports.home = function(req, res) { res.end(); console.log('Still going, going...');
你需要return。例如,
return
exports.home = function(req, res) { return res.end(); console.log('I will never run...');
res.end()简单地完成并刷新对客户端的响应。然而,就像任何其他操作一样,它不会告诉 JavaScript 停止运行,因此我们需要显式return退出函数(尽管我可能会问为什么在刷新您实际上并不想要的响应后会有代码跑步...?)。
res.end()