@aptoma/hapi-graceful-stop

Hapi plugin for graceful stop

Stats

stars 🌟issues ⚠️updated 🛠created 🐣size 🏋️‍♀️
10Jul 2, 2019Dec 14, 2015Minified + gzip package size for @aptoma/hapi-graceful-stop in KB

Readme

hapi-graceful-stop

This plugin will listen on SIGINT singnals and execute server.stop() with configured timeout and execut process exit when done.

Installation

This module is installed via npm:

$ npm install @aptoma/hapi-graceful-stop

Example


const Hapi = require('hapi');

const server = new Hapi.Server();

server.register({register: require('@aptoma/hapi-graceful-stop'), options: {timeout: 2000}});

server.start();

Running function after server.stop() e.g for ending db connections.


const Hapi = require('hapi');

const server = new Hapi.Server();

const opts = {
    timeout: 2000, // optional, defaults to 5000 ms
    afterStopTimeout: 1000, // optional, defaults to 2000 ms
    afterStop: function (done) {
        // do cleanup
        done();
    }
};

server.register({register: require('@aptoma/hapi-graceful-stop'), options: opts});

server.start();

If you find any bugs or have a feature request, please open an issue on github!

The npm package download data comes from npm's download counts api and package details come from npms.io.