# @ocalan/graceful

> Gracefully exit server (Koa), database (Mongo/Mongoose), Bree job schedulers, Bull job schedulers, and custom handlers.

Latest version **1.1.0** (published 2021-11-13) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @ocalan/graceful
pnpm add @ocalan/graceful
yarn add @ocalan/graceful
bun add @ocalan/graceful
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2021-11-13 |
| First published | 2021-11-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.3 |
| Dependencies | 1 |
| Unpacked size | 12 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Nicholai Nissen |
| Maintainers | nicholai |
| Keywords | bree, bull, close, database, exception, exit, express, force, graceful, handler, kill, koa, lad, lass, mongo, monitor, node, pm2, process, queue, redis, reload, reloading, server, sighup, sigint, uncaught, worker |

## Links

- npm: https://www.npmjs.com/package/@ocalan/graceful
- Repository: https://github.com/Nicholaiii/graceful
- Issues: https://github.com/Nicholaiii/graceful/issues
- npm.io page: https://npm.io/package/@ocalan/graceful

## Dependencies (1)

- [debug](https://npm.io/package/debug.md) ^4.3.2

## Alternatives

- [angular-pipes](https://npm.io/package/angular-pipes.md) — 5.6K weekly downloads
- [@ng-web-apis/midi](https://npm.io/package/@ng-web-apis/midi.md) — 2.6K weekly downloads
- [happn-3](https://npm.io/package/happn-3.md) — 1.6K weekly downloads
- [@opensip-cli/lang-go](https://npm.io/package/@opensip-cli/lang-go.md) — 1.2K weekly downloads
- [mongoose-typescript](https://npm.io/package/mongoose-typescript.md) — 85 weekly downloads

## Recent versions

- 1.1.0 (latest) — 2021-11-13

## README

# [**@ocalan/graceful**](https://github.com/ocalan/graceful)

> Gracefully exit server (Koa), database (Mongo/Mongoose), Redis clients, Bree job schedulers, Bull job schedulers, and custom handlers.

> Forked from [@ladjs/graceful](https://github.com/ladjs/graceful) to add TypeScript definitions.


## Table of Contents

* [Install](#install)
* [Usage](#usage)
* [Contributors](#contributors)
* [License](#license)


## Install

[npm][]:

```sh
npm install @ocalan/graceful
```

[yarn][]:

```sh
yarn add @ocalan/graceful
```


## Usage

Using this package will bind process event listeners when `graceful.listen()` is called:

* `process.on('warning')` - will output via `config.logger.warn`
* `process.on('unhandledRejection')` - will output via `config.logger.error`
* `process.once('uncaughtException')` - will output via `config.logger.error` and `process.exit(1)` (*does not exit gracefully*)
* `process.on('message')` - support Windows (e.g. signals not available) and listen for message of `shutdown` and then exit gracefully
* `process.once('SIGTERM')` - will exit gracefully
* `process.once('SIGHUP')` - will exit gracefully
* `process.once('SIGINT')` - will exit gracefully
* `process.once('SIGUSR2')` - will exit gracefully (nodemon support)

This package also prevents multiple process/SIG events from triggering multiple graceful exits. Only one graceful exit can occur at a time.

See one of these following files from [Lad][] for the most up to date usage example:

* API - <https://github.com/ladjs/lad/blob/master/template/api.js>
* Web - <https://github.com/ladjs/lad/blob/master/template/web.js>
* Bull - <https://github.com/ladjs/lad/blob/master/template/bull.js>
* Proxy - <https://github.com/ladjs/lad/blob/master/template/proxy.js>

You can also read more about Bree at <https://github.com/breejs/bree>.


## Contributors

| Name                | Website                        |
| ------------------- | ------------------------------ |
| **Nick Baugh**      | <http://niftylettuce.com/>     |
| **Felix Mosheev**   | <https://github.com/felixmosh> |
| **Nicholai Nissen** | <https://nicholai.dev>         |


## License

[MIT](LICENSE) © [Nicholai Nissen](https://nicholai.dev)


##

[npm]: https://www.npmjs.com/

[yarn]: https://yarnpkg.com/

[lad]: https://lad.js.org

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