UNPKG

ninjs-lodash

Version:
30 lines (24 loc) 1.04 kB
'use strict' const _ = require('lodash') module.exports = cleanup _.mixin({ cleanup: cleanup }) // attach user callback to the process event emitter // if no callback, it will still exit gracefully on Ctrl-C function cleanup(callback) { callback = callback || function() {} process.on('cleanup', callback); // do app specific cleaning before exiting process.on('exit', () => { process.emit('cleanup') }) // catch ctrl+c event and exit normally process.on('SIGINT', () => { console.log('Ctrl-C...'); process.exit(2) }) //catch uncaught exceptions, trace, then exit normally process.on('uncaughtException', (e) => { console.log('Uncaught Exception...'); console.log(e.stack); process.exit(99) }) } // USE BELOW ONLY FOR TESTING! // Emits an uncaught exception when called because module does not exist // exports.error = function() { // console.log('error') // var x = require('') // } // Prevents the program from closing instantly // exports.resume = function() { process.stdin.resume() }