# ondeath

> onDeath() will register callbacks to call right before your Node.js program terminates.

Latest version **1.0.0** (published 2018-06-21) · (ISC OR GPL-3.0) license · 0 weekly downloads

## Install

```sh
npm install ondeath
pnpm add ondeath
yarn add ondeath
bun add ondeath
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-21 |
| First published | 2018-06-21 |
| Weekly downloads | 0 |
| License | (ISC OR GPL-3.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alfred Godoy |
| Maintainers | alfredgodoy |
| Keywords | terminate, terminates, termination, quit, quits, exit, exits, death, dead |

## Links

- npm: https://www.npmjs.com/package/ondeath
- Repository: https://github.com/alfreddatakillen/ondeath
- Homepage: https://github.com/alfreddatakillen/ondeath#readme
- Issues: https://github.com/alfreddatakillen/ondeath/issues
- npm.io page: https://npm.io/package/ondeath

## Recent versions

- 1.0.0 (latest) — 2018-06-21

## README

onDeath()
=========

Syntax: `onDeath(callbackFn, options);`

The `callbackFn` will run just before the Node.js process exits.

The options
-----------

The options object is by default:

```
{
    SIGINT: true,
    SIGHUP: true,
    SIGQUIT: true,
    SIGTERM: true,
    uncaughtException: true,
    exit: true
}
```

You can override the defaults:

```
// Override uncaughtException:
onDeath(myCleanUpFn, { uncaughtException: false });
```

Abort program termination
-------------------------

The `callbackFn` can abort program termination by returning `false`, if the termination was triggered by
`SIGINT`, `SIGHUP`, `SIGQUIT`, `SIGTERM` or an unhandled exception. In other cases, it is not possible to
abort program termination.

Note! ALL your callbacks WILL run when the program is about to terminate. If your first callback returns
`false`, the other callbacks will still run. Then, program termination is aborted after all callbacks has
finished.

Regarding asynchronous clean up functions
-----------------------------------------

If you have asynchronous clean up jobs, you could return `false` to abort program termination, and then do a
`process.exit()` yourself when your asynch jobs are finished. However, as stated above, it is not always
possible to abort program termination.

---
_Source: https://npm.io/package/ondeath · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
