@redneckz/node-terminator
v0.0.4
Published
NodeJS graceful shutdown utility
Downloads
2
Readme
node-terminator
Handle NodeJS termination (SIGTERM/SIGINT) gracefully.
Installation
npm install --save @redneckz/node-terminator
How-to
Create NodeTerminator instance and attach it to NodeJS process (several instances can be created and attached).
const { NodeTerminator } = require('@redneckz/node-terminator');
const nodeTerminator = new NodeTerminator();
nodeTerminator.attach(() => {
// Some additional steps before exit
process.exit();
});
Decorate async jobs to control gracefull shutdown.
const {
graceful, // HOF bound to NodeTerminator instance
} = nodeTerminator;
const someJob = graceful(async () => {
// Do something asynchronously
console.log('Working hard...');
});