node.js可以检测它何时关闭?

时间:2014-01-21 23:29:44

标签: node.js

我想知道是否可以通过单击Windows上的“X”来检测node.js进程何时关闭。如果是,那怎么样。我尝试了process.on("exit");但是没有用。

1 个答案:

答案 0 :(得分:4)

抓住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();
});
相关问题