[英]Error: Not running on server.close()
我有一個錯誤不僅在我在服務器上啟動app.js時運行,它可以在localhost上運行。
我的代碼在那兒: Github
Error: Not running
at Server.close (net.js:1233:11)
at Object.<anonymous> (/home/Nahis_Wayard/summoner-infos/app.js:13:10)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:902:3
編輯:我刪除了'server.close()',現在它可以在任何地方使用
謝謝你的幫助 !
在您的app.js
,此代碼var server = http.createServer(app);
用來。
但是, http.createServer()
是異步函數,它返回http.Server
的新實例,並且http.server
繼承自net.Server
並具有其他events
。
因此,調用server.close()
可能會導致錯誤Error: Not running
在您的情況下Error: Not running
。
這是一個示例代碼,顯示了close()
的調用。
var server = http.createServer( (req, res) => {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('okay');
});
server.listen(1337, '127.0.0.1', () => {
// other operations here
server.close();
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.