我正在按照 此处 的指导(监听 SIGINT
事件)正常关闭我的 Windows-8 托管的 node.js 应用程序以响应 Ctrl
+ C
或服务器关闭。
但是 Windows 没有 SIGINT
。我也试过 process.on('exit')
,但这似乎晚了做任何有成效的事情。
在 Windows 上,这段代码给了我: 错误:没有这样的模块
process.on( 'SIGINT', function() {
console.log( "\ngracefully shutting down from SIGINT (Crtl-C)" )
// wish this worked on Windows
process.exit( )
})
在 Windows 上,此代码运行,但 为时已晚,无法优雅地执行任何操作:
process.on( 'exit', function() {
console.log( "never see this log message" )
})
Windows 上是否有 SIGINT
等效事件?
原文由 Q 4 发布,翻译遵循 CC BY-SA 4.0 许可协议
您必须使用 readline 模块并监听 SIGINT 事件:
http://nodejs.org/api/readline.html#readline_event_sigint