fastify-graceful-shutdown
TypeScript icon, indicating that this package has built-in type declarations

3.5.3 • Public • Published

🏹 fastify-graceful-shutdown

styled with prettier NPM version

Shutdown Fastify graceful asynchronously. By default the fastify close hook is called when SIGINT or SIGTERM was triggered.

Features

  • Graceful and debug friendly shutdown
  • Flush the fastify logger before process exit to avoid losing logs
  • Handlers are called in parallel for faster shutdown

Install

npm install --save fastify-graceful-shutdown

Register plugin

fastify.register(require('fastify-graceful-shutdown'))

Usage

fastify.after(() => {
  fastify.gracefulShutdown((signal, next) => {
    fastify.log.info('Received signal to shutdown: %s', signal)
    next()
  })
})

Compatibility

Fastify >=3

Caveats

  • Don't register signal handlers otherwise except with this plugin.
  • Can't be used with a different logger other than Pino because we use the child logger feature to encapsulate the logs.
  • Use fastify onClose hook to release resources in your plugin.
  • The process will be exited after a certain timeout (Default 10 seconds) to protect against stuck process.

Package Sidebar

Install

npm i fastify-graceful-shutdown

Weekly Downloads

25,626

Version

3.5.3

License

ISC

Unpacked Size

7.32 kB

Total Files

5

Last publish

Collaborators

  • starptech