Installations
npm install @almonds/http-shutdown
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>= 0.12.0
Node Version
11.10.0
NPM Version
6.7.0
Score
68.4
Supply Chain
84.6
Quality
75
Maintenance
100
Vulnerability
100
License
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
thedillonb
Download Statistics
Total Downloads
1,231
Last Day
3
Last Week
4
Last Month
14
Last Year
129
GitHub Statistics
MIT License
175 Stars
41 Commits
21 Forks
12 Watchers
1 Branches
8 Contributors
Updated on Dec 05, 2024
Bundle Size
991.00 B
Minified
470.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.2.1-rc.2
Package Id
@almonds/http-shutdown@1.2.1-rc.2
Unpacked Size
9.11 kB
Size
4.13 kB
File Count
8
NPM Version
6.7.0
Node Version
11.10.0
Total Downloads
Cumulative downloads
Total Downloads
1,231
Last Day
0%
3
Compared to previous day
Last Week
300%
4
Compared to previous week
Last Month
-41.7%
14
Compared to previous month
Last Year
-42.4%
129
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Http-Shutdown

Shutdown a Nodejs HTTP server gracefully by doing the following:
- Close the listening socket to prevent new connections
- Close all idle keep-alive sockets to prevent new requests during shutdown
- Wait for all in-flight requests to finish before closing their sockets.
- Profit!
Other solutions might just use server.close
which only terminates the listening socket and waits for other sockets to close - which is incomplete since keep-alive sockets can still make requests. Or, they may use ref()/unref()
to simply cause Nodejs to terminate if the sockets are idle - which doesn't help if you have other things to shutdown after the server shutsdown.
http-shutdown
is a complete solution. It uses idle indicators combined with an active socket list to safely, and gracefully, close all sockets. It does not use ref()/unref()
but, instead, actively closes connections as they finish meaning that socket 'close' events still work correctly since the sockets are actually closing - you're not just unref
ing and forgetting about them.
Installation
1$ npm install http-shutdown
Usage
There are currently two ways to use this library. The first is explicit wrapping of the Server
object:
1// Create the http server 2var server = require('http').createServer(function(req, res) { 3 res.end('Good job!'); 4}); 5 6// Wrap the server object with additional functionality. 7// This should be done immediately after server construction, or before you start listening. 8// Additional functionailiy needs to be added for http server events to properly shutdown. 9server = require('http-shutdown')(server); 10 11// Listen on a port and start taking requests. 12server.listen(3000); 13 14// Sometime later... shutdown the server. 15server.shutdown(function() { 16 console.log('Everything is cleanly shutdown.'); 17});
The second is implicitly adding prototype functionality to the Server
object:
1// .extend adds a .withShutdown prototype method to the Server object 2require('http-shutdown').extend(); 3 4var server = require('http').createServer(function(req, res) { 5 res.end('God job!'); 6}).withShutdown(); // <-- Easy to chain. Returns the Server object 7 8// Sometime later, shutdown the server. 9server.shutdown(function() { 10 console.log('Everything is cleanly shutdown.'); 11});

No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 7/20 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 19 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2025-02-17
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