且构网

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

请求完成后,nodejs表示关闭服务器

更新时间:2022-01-28 07:34:42

用于从http.Server继承的Express应用程序,它们不再这样做,而这正是close方法的来源.而是在您的srv实例上调用close().您可能通常会看到此代码写为:

Express applications used to inherit from http.Server, which they no longer do, and that's where the close method came from. Instead, call close() on your srv instance. You may commonly see this code written as:

var app = express.createServer();
var srv = require('http').createServer(app);
srv.listen(port);

根据app.listen()文档:

绑定并侦听给定主机和端口上的连接,此方法与节点的http.Server#listen()相同.