tiny module to log and exit on uncaughtException and unhandledRejection events
npm install perish



tiny module to log and exit on uncaughtException and unhandledRejection events
npm install --save(-dev) perish
require('perish')
that's all. in any nodejs file.
listen for uncaughtException & unhandledRejection in node processes. when those events occur, log the message and the stack, then exit with exit code 1.
because apps should die hard if their errors aren't handled. some apps require graceful exit onerror. sometimes this is feasible, sometimes this is not. this package is simple and just exits.
js
// unhandled.js
Promise.reject(new Error('bananas'))
`run
node unhandled.js and ... nothing.`js
// handled.js
require('perish')
Promise.reject(new Error('bananas'))
`run
node handled.js and:`js
Error: bananas
at Object. (/some/path/handled.js:2:16)
at Module._compile (module.js:541:32)
at Object.Module._extensions..js (module.js:550:10)
at Module.load (module.js:458:32)
at tryModuleLoad (module.js:417:12)
at Function.Module._load (module.js:409:3)
at Function.Module.runMain (module.js:575:10)
at startup (node.js:160:18)
at node.js:456:3 `nothin' too fancy!
api
`js
const perish = require('perish')
perish.printStacktrace // default true. set to false to console.error error message only
perish.fail // @private. this is the error handler
``