@ocalan/gracefuldeprecated

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

Usage no npm install needed!

<script type="module">
  import ocalanGraceful from 'https://cdn.skypack.dev/@ocalan/graceful';
</script>

README

@ocalan/graceful

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

Forked from @ladjs/graceful to add TypeScript definitions.

Table of Contents

Install

npm:

npm install @ocalan/graceful

yarn:

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:

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 © Nicholai Nissen