Created
May 20, 2015 03:41
-
-
Save bencooling/212e9bca0538007c7577 to your computer and use it in GitHub Desktop.
nodejs process lifecycle events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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