https://github.com/cdaringe/perish
tiny module to log and exit on uncaughtException and unhandledRejection events
https://github.com/cdaringe/perish
Last synced: 10 months ago
JSON representation
tiny module to log and exit on uncaughtException and unhandledRejection events
- Host: GitHub
- URL: https://github.com/cdaringe/perish
- Owner: cdaringe
- License: mit
- Created: 2016-06-09T02:49:18.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-05T18:42:05.000Z (almost 2 years ago)
- Last Synced: 2025-04-22T16:02:50.370Z (about 1 year ago)
- Language: JavaScript
- Size: 777 KB
- Stars: 2
- Watchers: 2
- Forks: 3
- Open Issues: 23
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# perish
[](https://codeship.com/projects/157001)
[](https://coveralls.io/github/cdaringe/perish?branch=master)

[](https://www.typescriptlang.org)
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
```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
```