0.1.0 • Published 6 years ago

pm2-state-helper v0.1.0

Weekly downloads
19
License
ISC
Repository
github
Last release
6 years ago

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.