Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
express-graceful-exit
Advanced tools
Allow graceful exits for express apps, supporting zero downtime deploys
A component in having zero downtime deploys for Node.js with Express. It was developed for Express 3.X, so it may need work to be compatible with Express 2.X
This module was originally developed for Frafty, a Daily Fantasy Sports site.
$ cd /path/to/your/project
$ npm install express-graceful-exit
v0.X.X versions are backwards API compatible, with the caveate that process exit is called in a setTimeout
block from v0.2.0 forward, so the timing is slightly different between v0.1.0 to v0.2.x+.
The following two components must both be used to enable fully graceful exits.
This middleware should be the very first middleware that gets setup with your Express app.
var express = require('express');
var app = express();
var gracefulExit = require('express-graceful-exit');
app.use(gracefulExit.middleware(app));
This function tells express to accept no new requests and gracefully closes the http server. It can be attached to a signal, or used as a normal function call if another tool is used (such as naught).
// Example for naught
process.on('message', function(message) {
if (message === 'shutdown') {
gracefulExit.gracefulExitHandler(app, server, {
socketio: app.settings.socketio
});
}
});
There are no options available currently.
The following options are available:
Option | Description | Default |
---|---|---|
log | Print status messages and errors to the logger | false |
logger | Function that accepts a string to output a log message | console.log |
callback | Optional function that is called with the exit status code once express has shutdown, gracefully or not Use in conjunction with exitProcess: false when the caller handles process shutdown | no-op |
exitProcess | If true, the module calls process.exit() when express has shutdown, gracefully or not | true |
exitDelay | Wait timer duration in the final internal callback (triggered either by gracefulExitHandler or the suicideTimeout) if exitProcess: true | 10ms |
suicideTimeout | How long to wait before giving up on graceful shutdown, then returns exit code of 1 | 2m 10s (130s) |
socketio | An instance of socket.io , used to close all open connections after timeout | none |
force | Instructs the module to forcibly close sockets once the suicide timeout elapses. For this option to work you must call gracefulExit.init(server) when initializing the HTTP server | false |
To gracefully exit this module will do the following things:
0
suicideTimeout
ms, the handler returns 1
process.exit
This module does not give you zero downtime deploys on its own. It enables the http server to exit gracefully, which when used with a module like naught can provide zero downtime deploys.
FAQs
Allow graceful exits for express apps, supporting zero downtime deploys
We found that express-graceful-exit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.