Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    hapi-shutdownpublic

    Hapi-shutdown

    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', ...)

    Usage:

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

    .register(task)

    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
        done()
      },
      timeout: 2000 // time in ms to wait for the task to complete
    }
    

    Returns: a joi validation error for the task.

    Logging:

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

    Keywords

    install

    npm i hapi-shutdown

    Downloadsweekly downloads

    68

    version

    1.0.0

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar
    • avatar
    • avatar
    • avatar
    • avatar