Skip to content

Instantly share code, notes, and snippets.

@aGuyNamedJonas
Last active January 3, 2018 13:27
Show Gist options
  • Save aGuyNamedJonas/9cdf8cc4a92aeee2e7cf478ea6154983 to your computer and use it in GitHub Desktop.
Save aGuyNamedJonas/9cdf8cc4a92aeee2e7cf478ea6154983 to your computer and use it in GitHub Desktop.
process.stdin.resume();//so the program will not close instantly
function exitHandler(options, err) {
if (options.cleanup) console.log('clean');
if (err) console.log(err.stack);
if (options.exit) process.exit();
}
//do something when app is closing
process.on('exit', exitHandler.bind(null,{cleanup:true}));
//catches ctrl+c event
process.on('SIGINT', exitHandler.bind(null, {exit:true}));
//catches uncaught exceptions
process.on('uncaughtException', exitHandler.bind(null, {exit:true}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment