Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @ladjs/graceful with all npm packages installed. Try it out:

var graceful = require("@ladjs/graceful")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@ladjs/graceful v1.0.0

Gracefully exit server (Koa), database (Mongo/Mongoose), and job scheduler (Redis/Bull)

@ladjs/graceful

build status code coverage code style styled with prettier made with lass license

Gracefully exit server (Koa), database (Mongo/Mongoose), Redis clients, and job scheduler (Redis/Bull)

Table of Contents

Install

npm:

npm install @ladjs/graceful

yarn:

yarn add @ladjs/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:

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

License

MIT © Nick Baugh

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free