perish
tiny module to log and exit on uncaughtException and unhandledRejection events
install
npm install --save(-dev) perish
usage
require('perish')
that's all. in any nodejs file.
what
listen for uncaughtException
& unhandledRejection
in node processes. when those events occur, log the message and the stack, then exit with exit code 1
.
why
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.
example
// unhandled.jsPromise
run node unhandled.js
and ... nothing.
// handled.jsPromise
run node handled.js
and:
Error: bananas at Object<anonymous> /some/path/handledjs:2:16 at Module at ObjectModule_extensions at Module at at FunctionModule at FunctionModule at at nodejs:456:3
nothin' too fancy!
api
const perish = perishprintStacktrace // default true. set to false to console.error error message onlyperishfail // @private. this is the error handler