Gathering detailed insights and metrics for express-graceful-shutdown-handler-patched
Gathering detailed insights and metrics for express-graceful-shutdown-handler-patched
Gathering detailed insights and metrics for express-graceful-shutdown-handler-patched
Gathering detailed insights and metrics for express-graceful-shutdown-handler-patched
Middleware to handle graceful shutdown on any uncaught exception.
npm install express-graceful-shutdown-handler-patched
Typescript
Module System
Node Version
NPM Version
CoffeeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
3 Stars
11 Commits
2 Forks
19 Watchers
1 Branches
11 Contributors
Updated on Dec 05, 2020
Latest Version
1.0.3
Package Id
express-graceful-shutdown-handler-patched@1.0.3
Unpacked Size
8.63 kB
Size
3.33 kB
File Count
4
NPM Version
8.15.0
Node Version
18.7.0
Published on
Feb 23, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
[![NPM Version][npm-image]][npm-url] [![NPM Downloads][downloads-image]][downloads-url]
Middleware to handle graceful shutdown on any uncaught exception.
After encountering an exception this middleware stops accepting new requests, waits for the user's exception handler and all currently running requests to finish within a certain grace period and exits.
1$ npm install express-graceful-shutdown-handler-patched
1var gracefulShutdown = require('express-graceful-shutdown-handler-patched') 2
Note Requiring the module adds a uncaughtException
listener.
Creates a graceful shutdown middleware with the given options
.
Note Make sure it's attached as the first middleware.
Create a new domain and bind request and response to it. This enables the library to return 500 error on the request that caused an unhandled exception to happen, instead of severing the connection.
The default value is true
.
If domainEnabled
is set to true, you can look at process.domain.id
in your onExceptionFn
to see the unique request id. This function is given req
and is expected to return this id.
The default behavior is to return an incremented number for each request.
Sets a function which will be called in the event of an unhandled exception. The function is given err
as the first argument and callback
as the second argument.
The default value is a call to console.error
.
Controls the grace period which is given for your exception handler and currently running requests to finish. If they are not completed within this time, process is killed anyway.
The default value is 15
.
Control the status which is returned for any new request done after the shutdown process is started. Use it in your load balancer (e.g. nginx
) to redirect the request to another server.
The default value is 503
.
A simple example using express-graceful-shutdown-handler-patched
to log the exception asynchronously (for example to Slack), waiting for the logger to complete the request.
1var express = require('express') 2var gracefulShutdown = require('express-graceful-shutdown-handler-patched') 3 4var app = express() 5 6### 7Unhandled exceptions handling w/ graceful shutdown. 8### 9 10app.use(gracefulShutdown({ 11 onExceptionFn: function (err, callback) { logger.error(err, callback); } 12})) 13 14app.get('/cause_exc', function (req, res, next) { 15 setTimeout(function() { 16 throw new Error("Error!"); 17 }, 1000); 18}) 19 20app.get('/long_running_request', function (req, res, next) { 21 setTimeout(function() { 22 res.sendStatus(200); 23 }, 10000); 24})
Use curl
to fetch the /long_running_request
route, then immediately after fetch the /cause_exc
route.
You'll see the exception logged to the console and the first request to finish before server is killed.
Every consecutive request will return with HTTP status code 503
.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/11 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More