Gathering detailed insights and metrics for @moebius/http-graceful-shutdown
Gathering detailed insights and metrics for @moebius/http-graceful-shutdown
npm install @moebius/http-graceful-shutdown
Typescript
Module System
Node Version
NPM Version
99.1
Supply Chain
99.4
Quality
75
Maintenance
100
Vulnerability
100
License
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
8,517,747
Last Day
7,735
Last Week
45,873
Last Month
184,595
Last Year
2,027,766
Minified
Minified + Gzipped
Latest Version
1.1.0
Package Id
@moebius/http-graceful-shutdown@1.1.0
Unpacked Size
9.42 kB
Size
3.79 kB
File Count
8
NPM Version
6.1.0
Node Version
9.11.1
Cumulative downloads
Total Downloads
Last Day
-21.2%
7,735
Compared to previous day
Last Week
11.6%
45,873
Compared to previous week
Last Month
13.6%
184,595
Compared to previous month
Last Year
-14.3%
2,027,766
Compared to previous year
2
This package for Node.js provides you with easy to use facilities required to gracefully terminate HTTP servers.
It's designed to work with native http.Server
implementation, so it
could be used for any server build on top of it (i.e. Express and other).
See examples below.
When your application's process is interrupted by the operating system (by passing SIGINT or SIGTERM signals) by default the server is terminated right away and all open connections are brutally severed. This means that if some client was in the process of sending or receiving data from your server it will encounter an error. This could easily lead to escalating errors down the chain and data corruption.
The better strategy would be to listen for interruption signals and to close connections gracefully by closing only idle connections right away and waiting for pending requests to properly complete.
This module solves exactly this problem (or at least the second part of it).
Install package with yarn:
yarn add @moebius/http-graceful-shutdown
Or npm:
npm i -S @moebius/http-graceful-shutdown
1const http = require('http'); 2const GracefulShutdownManager = require('@moebius/http-graceful-shutdown').GracefulShutdownManager; 3 4 5const server = http.createServer(/** … */); 6const shutdownManager = new GracefulShutdownManager(server); 7 8server.listen(8080); 9 10process.on('SIGTERM', () => { 11 shutdownManager.terminate(() => { 12 console.log('Server is gracefully terminated'); 13 }); 14});
1const express = require('express'); 2const GracefulShutdownManager = require('@moebius/http-graceful-shutdown').GracefulShutdownManager; 3 4 5const app = express(); 6 7const server = app.listen(8080); 8 9const shutdownManager = new GracefulShutdownManager(server); 10 11process.on('SIGTERM', () => { 12 shutdownManager.terminate(() => { 13 console.log('Server is gracefully terminated'); 14 }); 15});
construct (server: http.Server)
Creates an instance of GracefulShutdownManager
class.
The server
argument is a Node.js HTTP server instance, i.e. http.Server
.
If you are using Express, you can obtain it like this: const server = app.listen(/** … */);
terminate(callback: Function)
Initiates graceful termination of the server by closing all idle connections first and then by waiting for pending requests to finish. New requests are not accepted after calling this.
If you like this module please consider to add a star on GitHub repository.
Thank you!
The MIT License (MIT)
Copyright (c) 2017 Slava Fomin II, MOEBIUS FOUNDATION.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
No vulnerabilities found.
No security vulnerabilities found.