about
exit-gracefully
is a zero dependency module that helps with exiting gracefully from a nodejs process, it's an event listener that allows for subscribing exit events that'll need to be complete before process.exit()
is called
installation
npm install --save exit-gracefully
by example
exit-gracefully
has a pretty short simple code, the easiest way would be to just read through it
simplest use
const exitGracefully = // this only needs to be done once in your codebase, this connects to process events, can provided as an array or single strings// if you dont attach any event exitGracefully wouldnt be of much useexitGracefully exitGracefully
more complex use cases
const exitGracefully = exitGracefully // connect specific signals onlyexitGracefullyexitGracefully // change exit code for a signalexitGracefully // EXIT_CODES.NORMAL is the default // trigger a graceful exitexitGracefully // EXIT_CODES.NORMAL is the default // trigger a graceful exit with an error attachedexitGracefully // EXIT_CODES.NORMAL is the default // if an exit process exists with done(error) you can get it hereexitGracefully // do some stuff before an exit, you can not do any async stuff here, you only have one tickexitGracefully { { // hurry up and finish } exitGracefully // do normal stuff // done normally, we wouldnt need the exit anymore exitGracefully}
License: MIT