README
PM2-State-Helper - Exit With Grace
Intro
Simple module which allows a process running under PM2 to start and stop gracefully.
const state = require('pm2-state-helper');
const server = require('http').createServer();
// Handle stopping
state.onStopping(callback => {
// Handle your stuff here...
// Do stuff...
// Do stuff...
server.close(callback); // Finally let us know its over
});
// Notify start
server.listen('8080', () => {
state.started();
});
Notes
onStopping
also accepts a function that returns a Promise
instead of one accepting the callback.