@bookmate/with-express-graceful-shutdown

0.0.1 • Public • Published

Graceful Shutdown

Summary

This is a decorator for an Express http server enabling its graceful shutdown.

Based on ideas from:

  1. express-graceful-shutdown middleware, which in turn used this blog post for inspiration;

  2. http-shutdown module

Installation

npm install @bookmate/with-express-graceful-shutdown --save

Usage

const withGracefulShutdown = require('@bookmate/with-express-graceful-shutdown');
const app = require('./app'); // a regular Express app
const logger = require('./logger') // a custom logger

const expressPort = 3000;
const forceTimout = 30 * 1000; // timeout after which the app should be shut down forcefully

const options = {
  logger,
  forceTimout
}

const server = app.listen(expressPort, () => {
  // your server is running
});

withGracefulShutdown(server, options);

Options

  • logger: a logger that provides info, warn, and error functions for recording graceful shutdown. Default: console.

  • forceTimeout: number of milliseconds to wait for server.close() to complete before calling process.exit(1). Default: 60000.

Readme

Keywords

none

Package Sidebar

Install

npm i @bookmate/with-express-graceful-shutdown

Weekly Downloads

32

Version

0.0.1

License

ISC

Unpacked Size

3.91 kB

Total Files

3

Last publish

Collaborators

  • andorn
  • bookmate-npm