node.js怎么监听程序强制退出?
PHPz
PHPz 2017-04-17 13:04:49
0
3
653

java中可以用Runtime.getRuntime().addShutdownHook();来监听退出事件,所以可以在退出前做一些状态清理的工作,在IDE中强制退出也能捕捉到;

在node.js中我用process.on('exit')为什么不能捕捉到IDE中退出事件呢?

PHPz
PHPz

学习是最好的投资!

reply all(3)
迷茫

https://nodejs.org/api/process.html#process_event_exit

This event is only emitted when node exits explicitly by process.exit() or implicitly by the event loop draining.

PHPzhong

Cannot monitor
Forced exit semaphore cannot add callback function in node

黄舟

I don’t know what command is sent to force exit in the IDE
In nodejs, you can listen to the exit of the program by listening to the semaphore
For example, SIGINT listens to ctrl-D/Control-C to exit the program

process.on('SIGINT', function() {
  console.log('Got SIGINT.  Press Control-D/Control-C to exit.');
});
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template