Skip to content

Instantly share code, notes, and snippets.

@patbonecrusher
Created September 28, 2017 20:25
Show Gist options
  • Save patbonecrusher/3f46bb45f78917eb225c912207e59bb9 to your computer and use it in GitHub Desktop.
Save patbonecrusher/3f46bb45f78917eb225c912207e59bb9 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