Gathering detailed insights and metrics for http-terminator
Gathering detailed insights and metrics for http-terminator
Gathering detailed insights and metrics for http-terminator
Gathering detailed insights and metrics for http-terminator
lil-http-terminator
Zero dependencies, gracefully terminates HTTP(S) server.
@types/http-terminator
Stub TypeScript definitions entry for http-terminator, which provides its own types definitions
@yocdev/http-terminator
Gracefully terminates HTTP(S) server.
@kikobeats/http-terminator
Gracefully terminates HTTP(S) server.
npm install http-terminator
Typescript
Module System
Min. Node Version
Node Version
NPM Version
98.9
Supply Chain
99.5
Quality
75.7
Maintenance
100
Vulnerability
100
License
TypeScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
NOASSERTION License
330 Stars
61 Commits
26 Forks
4 Watchers
1 Branches
6 Contributors
Updated on Apr 28, 2025
Latest Version
3.2.0
Package Id
http-terminator@3.2.0
Unpacked Size
22.92 kB
Size
6.42 kB
File Count
19
NPM Version
7.24.2
Node Version
14.19.0
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
Gracefully terminates HTTP(S) server.
When you call server.close()
, it stops the server from accepting new connections, but it keeps the existing connections open indefinitely. This can result in your server hanging indefinitely due to keep-alive connections or because of the ongoing requests that do not produce a response. Therefore, in order to close the server, you must track creation of all connections and terminate them yourself.
http-terminator implements the logic for tracking all connections and their termination upon a timeout. http-terminator also ensures graceful communication of the server intention to shutdown to any clients that are currently receiving response from this server.
1import { 2 createHttpTerminator, 3} from 'http-terminator'; 4 5/** 6 * @property gracefulTerminationTimeout Number of milliseconds to allow for the active sockets to complete serving the response (default: 5000). 7 * @property server Instance of http.Server. 8 */ 9type HttpTerminatorConfigurationInputType = {| 10 +gracefulTerminationTimeout?: number, 11 +server: Server, 12|}; 13 14/** 15 * @property terminate Terminates HTTP server. 16 */ 17type HttpTerminatorType = {| 18 +terminate: () => Promise<void>, 19|}; 20 21 22const httpTerminator: HttpTerminatorType = createHttpTerminator( 23 configuration: HttpTerminatorConfigurationInputType 24); 25
Use createHttpTerminator
to create an instance of http-terminator and instead of using server.close()
, use httpTerminator.terminate()
, e.g.
1import http from 'http'; 2import { 3 createHttpTerminator, 4} from 'http-terminator'; 5 6const server = http.createServer(); 7 8const httpTerminator = createHttpTerminator({ 9 server, 10}); 11 12await httpTerminator.terminate(); 13
Usage with Express example:
1import express from 'express'; 2import { 3 createHttpTerminator, 4} from 'http-terminator'; 5 6const app = express(); 7 8const server = app.listen(); 9 10const httpTerminator = createHttpTerminator({ 11 server, 12}); 13 14await httpTerminator.terminate(); 15
Usage with Fastify example:
1import fastify from 'fastify'; 2import { 3 createHttpTerminator, 4} from 'http-terminator'; 5 6const app = fastify(); 7 8void app.listen(0); 9 10const httpTerminator = createHttpTerminator({ 11 server: app.server, 12}); 13 14await httpTerminator.terminate(); 15
Usage with Koa example:
1import Koa from 'koa'; 2import { 3 createHttpTerminator, 4} from 'http-terminator'; 5 6const app = new Koa(); 7 8const server = app.listen(); 9 10const httpTerminator = createHttpTerminator({ 11 server, 12}); 13 14await httpTerminator.terminate(); 15
As it should be clear from the usage examples for Node.js HTTP server, Express and Koa, http-terminator works by accessing an instance of a Node.js http.Server
. To understand how to use http-terminator with your framework, identify how to access an instance of http.Server
and use it to create a http-terminator instance.
There are several alternative libraries that implement comparable functionality, e.g.
The main benefit of http-terminator is that:
connection: close
headerTo gracefully terminate a HTTP server.
We say that a service is gracefully terminated when service stops accepting new clients, but allows time to complete the existing requests.
There are several reasons to terminate services gracefully:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/22 approved changesets -- score normalized to 1
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
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
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