我有以下代码从终端捕获^ C并正常关闭我的Express应用程序:
process.on('SIGINT', () => {
console.log('SIGINT received ...');
console.log('Shutting down the server');
server.close(() => {
console.log('Server has been shutdown');
console.log('Exiting process ...');
process.exit(0);
});
});
Run Code Online (Sandbox Code Playgroud)
但是,如果我使用启动节点实例--inspect,则上述代码无法停止检查器和Chrome调试器.当我重新启动我的应用程序时,我收到以下错误:
Starting inspector on 127.0.0.1:9229 failed: address already in use
Run Code Online (Sandbox Code Playgroud)
如何优雅地停止我的应用程序以避免此错误?
可以使用完整的代码在这里.