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
npm install http-terminator
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
324 Stars
61 Commits
26 Forks
5 Watching
1 Branches
6 Contributors
Updated on 25 Sept 2024
TypeScript (100%)
Cumulative downloads
Total Downloads
Last day
-56.2%
104,745
Compared to previous day
Last week
2%
1,035,634
Compared to previous week
Last month
5.7%
4,007,287
Compared to previous month
Last year
78.1%
20,882,391
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 2024-11-25
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