Is there a way to run a function when the node.js process is killed?
This is what I'm aiming for (in C):
signal(SIGSEGV, sig_handler);
void sig_handler(int sig) {
if (sig == SIGSEGV) {
// do stuff
}
}
So, is it possible to do this in node.js?
Yep,
process.on('SIGINT', function() {
console.log('Got SIGINT. Press Control-D to exit.');
});
Taken from the documentation: