
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
@droidsolutions-oss/http-terminator
Advanced tools
(Based on http-terminator.)
Gracefully terminates HTTP(S) server. Also includes Typescript support.
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.
DroidSolutions http-terminator implements the logic for tracking all connections and their termination upon a timeout. It also ensures graceful communication of the server intention to shutdown to any clients that are currently receiving response from this server.
Use new HttpTerminator to create an instance of DroidSolutions http-terminator and instead of using server.close(), use httpTerminator.terminate().
import { HttpTerminator } from "@droidsolutions/http-terminator";
import http from "http";
const server = http.createServer();
const httpTerminator = new HttpTerminator(server);
await httpTerminator.terminate();
Usage with Express example:
import express from "express";
import { HttpTerminator } from "@droidsolutions/http-terminator";
const app = express();
const server = app.listen();
const httpTerminator = new HttpTerminator(server);
await httpTerminator.terminate();
You can specify an optional timeout in milliseconds to wait, before requests are closed forcefully. If you do not specify a timeout, the default of 1000 ms is used.
const httpTerminator = new HttpTerminator(server);
await httpTerminator.terminate(2000);
Usage with Koa example:
import Koa from "koa";
import { HttpTerminator } from "@droidsolutions/http-terminator";
const app = new Koa();
const server = app.listen();
const httpTerminator = new HttpTerminator(server);
await httpTerminator.terminate();
As it should be clear from the usage examples for Node.js HTTP server, Express and Koa, DroidSolutions http-terminator works by accessing an instance of a Node.js http.Server. To understand how to use DroidSolutions http-terminator with your framework, identify how to access an instance of http.Server and use it to create a HttpTerminator instance.
There are several alternative libraries that implement comparable functionality, e.g.
The main benefit of DroidSolutions 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:
FAQs
Gracefully terminates HTTP(S) server.
The npm package @droidsolutions-oss/http-terminator receives a total of 237 weekly downloads. As such, @droidsolutions-oss/http-terminator popularity was classified as not popular.
We found that @droidsolutions-oss/http-terminator 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
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.