2014-01-21 43 views
4

我想知道是否有可能通過單擊Windows上的'X'來檢測node.js進程何時關閉。如果是的話那麼怎麼樣我試過process.on("exit");但這沒有奏效。node.js能檢測它何時關閉嗎?

+0

如關閉瀏覽器窗口或關閉Windows中的一個窗口運行的節點?其中節點正在運行的 – adeneo

+0

窗口。 – auragar

+1

一旦節點不再運行,它就無法檢測到它沒有運行。 – adeneo

回答

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(); 
}); 
+0

SIGHUP工作。非常感謝。 – auragar