我想知道是否可以通过单击 Windows 上的“X”来检测 node.js 进程何时关闭。如果是,那么如何。我试过,process.on("exit");但没有奏效。
捕捉SIGHUP
/*
* Run this code and close the Window before the 10 seconds
*/
var x = setTimeout(function() { console.log('hello world') }, 10000);
process.on('SIGHUP', function() {
console.log('About to exit');
process.exit();
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2779 次 |
| 最近记录: |