Skip to content

Instantly share code, notes, and snippets.

@bencooling
Created May 20, 2015 03:41
Show Gist options
  • Save bencooling/212e9bca0538007c7577 to your computer and use it in GitHub Desktop.
Save bencooling/212e9bca0538007c7577 to your computer and use it in GitHub Desktop.
nodejs process lifecycle events
/* demonstrate process lifecycle
--------------------------------*/
console.log('Start process');
// Event is fired when user kills process (ctl+d)
process.on('SIGINT', function() {
console.log('I\'m dying.');
setTimeout(function(){
process.exit(1);
}, 1000);
});
// Event is fired when process exits
process.on('exit', function(code) {
console.log('exiting');
});
// This process will wait for 5 seconds before exiting
setTimeout(function(){
console.log('too late');
}, 5*1000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment