Module to handle graceful shutdowns

Module to handle applications’ graceful shutdowns.

This super simple module helps shutting down servers, database handles, etc. in NodeJS applications. It allows to register handlers for certain shutdown signals/events in order to attempt a graceful shutdown (clean-ups etc.)

NOTE: it removes any previous registered listeners for the given signals!

By default it listens to: SIGTERM SIGHUP SIGINT

It also listens to process.exit but keep in mind that exit does not allow asynchrounous listeners’ operations to complete (see process.exit on

It is also possible to add (or remove) other shutdown signals/events.


npm i -S @hypercliq/shutdown-cleanup


Register a handler

import { ShutdownCleanup } from 'shutdown-cleanup'
// const ShutdownCleanup = require('shutdown-cleanup').ShutdownCleanup

ShutdownCleanup.registerHandler(() => console.log('This is printed on exit :)'))

Add a signal or event to listen to


Remove a signal or an event


List signals and events listened to



TypeScript types are included.

Uncaught Exceptions & other similar events

It is possible to listen to the uncaughtException event, but no error message will be displayed if the handle function does not explicitly ask for it or we don’t enable debug (this is also true for other events such as unhandledRejection.)

Handle parameter
ShutdownCleanup.registerHandler((codeOrError) =>
  console.log('This what we got back:', codeOrError)

By accepting a parameter (in this case codeOrError) we can get back from the module either a code/signal or an error.


Another way to see what’s going on is to turn debug on:

DEBUG=shutdown-cleanup npm start

or Windows

set DEBUG=shutdown-cleanup & npm start

Download Details:

Author: hypercliq

Source Code:

#nodejs #node #javascript

Module to handle graceful shutdowns
9.75 GEEK