node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »



Build Status NPM version Dependencies

Plugin listens to SIGTERM and then runs optional triggers before calling server.stop

This is for things that need to happen before server.stop is called.

For things that need to happen after server.stop, you can use server.on('stop', ...)


var Hapi = require("hapi");
var server = new Hapi.Server();
    plugin: require('hapi-shutdown'),
    options: {
      serverSpindownTime: 10000 // time to wait for existing connections before forcibly stopping the server
        taskname: 'do stuff',
        task: function(done){ console.log('doing stuff before server.stop is called'); done(); },
        timeout: 2000 // time to wait


Register a task to be run before server.stop is called. Can be called as part of another plugin, or using server.after().

Param: task

  taskname: 'mytask', // used for logging and to guard against multiple registrations
  task: function(done){
    // do stuff
  timeout: 2000 // time in ms to wait for the task to complete

Returns: a joi validation error for the task.


Will log using 'server.log()' and the tag "shutdown"