# node-exit

> Broadcast exit event to listener before the actual exit handler is called

Latest version **1.2.2** (published 2019-04-27) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install node-exit
pnpm add node-exit
yarn add node-exit
bun add node-exit
```

## 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.2.2 |
| Published | 2019-04-27 |
| First published | 2018-04-25 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Qian Xu |
| Maintainers | stanleyxu2005 |
| Keywords | process, exit, shutdown, graceful |

## Links

- npm: https://www.npmjs.com/package/node-exit
- Repository: https://github.com/stanleyxu2005/node-exit
- Issues: https://github.com/stanleyxu2005/node-exit/issues
- npm.io page: https://npm.io/package/node-exit

## Recent versions

- 1.2.2 (latest) — 2019-04-27
- 1.2.1 — 2019-04-27
- 1.2.0 — 2019-04-27
- 1.1.0 — 2019-04-27
- 1.0.5 — 2019-04-24
- 1.0.4 — 2019-04-23
- 1.0.2 — 2018-04-25
- 1.0.1 — 2018-04-25
- 1.0.0 — 2018-04-25

## README

# Node-Exit

[![npm version](https://badge.fury.io/js/node-exit.svg)](http://badge.fury.io/js/node-exit)

A simple process exit hook to make sure you can run your clean up code before node process exits.

## Code Example

The application uses `pm2` to manage processes. When user presses <kbd>CTRL</kbd>+<kbd>C</kbd> to
kill application, the signal will be sent to child processes as well. `pm2` will try to recover
these processes. With this module, we can tell `pm2` no longer monit terminated processes.

In `app.js`

```javascript
const shutdown = require('node-exit')

shutdown.registerExitHandler((isExpectedExit, error) => {
  if (!isExpectedExit) {
    console.fatal('Unexpected exit', error)
  }
  // Put your clean up code here
})
```

If you have more than one exit handling, here is an example:

```javascript
const shutdown = require('node-exit')
const pm2 = require('pm2')

// Start PM2
const detached = false
pm2.connect(detached)

// Hook for stop
shutdown.on('will-exit', (isExpectedExit) => {
  console.debug('Will exit soon...')
  pm2.killDaemon()
})
```

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