{"id":23786228,"url":"https://github.com/the-moebius/http-graceful-shutdown","last_synced_at":"2026-03-14T09:40:20.303Z","repository":{"id":122006606,"uuid":"92971385","full_name":"the-moebius/http-graceful-shutdown","owner":"the-moebius","description":"Gracefully terminates HTTP servers in Node.js","archived":false,"fork":false,"pushed_at":"2022-12-07T01:02:11.000Z","size":20,"stargazers_count":89,"open_issues_count":5,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-06T04:38:08.685Z","etag":null,"topics":["express","graceful-shutdown","http","http-server"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/the-moebius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2017-05-31T17:30:30.000Z","updated_at":"2025-08-24T01:47:43.000Z","dependencies_parsed_at":null,"dependency_job_id":"08ffc458-bb21-4682-b96d-0a9eb09751e0","html_url":"https://github.com/the-moebius/http-graceful-shutdown","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/the-moebius/http-graceful-shutdown","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-moebius%2Fhttp-graceful-shutdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-moebius%2Fhttp-graceful-shutdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-moebius%2Fhttp-graceful-shutdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-moebius%2Fhttp-graceful-shutdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/the-moebius","download_url":"https://codeload.github.com/the-moebius/http-graceful-shutdown/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/the-moebius%2Fhttp-graceful-shutdown/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279010790,"owners_count":26084807,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["express","graceful-shutdown","http","http-server"],"created_at":"2025-01-01T14:13:47.961Z","updated_at":"2025-10-12T08:39:42.238Z","avatar_url":"https://github.com/the-moebius.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @moebius/http-graceful-shutdown\n\n[![npm version](https://badge.fury.io/js/%40moebius%2Fhttp-graceful-shutdown.svg)](https://badge.fury.io/js/%40moebius%2Fhttp-graceful-shutdown)\n\n\nThis package for Node.js provides you with easy to use facilities\nrequired to gracefully terminate HTTP servers.\n\nIt's designed to work with native `http.Server` implementation, so it\ncould be used for any server build on top of it (i.e. Express and other).\nSee [examples](#usage) below.\n\n\n## Features\n\n- Keeps track of all open connections and their status (active/idle)\n- Gracefully terminates all connections by terminating the idle ones right away\n  and waiting for pending requests to complete\n- Very straightforward and simple API to use\n- Minimal working implementation possible without extraneous functionality\n- Written in TypeScript, but supports vanilla JavaScript\n\n\n## Problem\n\nWhen your application's process is interrupted by the operating system\n(by passing SIGINT or SIGTERM signals) by default the server is terminated\nright away and all open connections are brutally severed. This means that\nif some client was in the process of sending or receiving data from your\nserver it will encounter an error. This could easily lead to escalating errors\ndown the chain and data corruption.\n\nThe better strategy would be to listen for interruption signals and to close\nconnections gracefully by closing only idle connections right away and waiting\nfor pending requests to properly complete.\n\nThis module solves exactly this problem (or at least the second part of it).\n\n\n## Installation\n\nInstall package with yarn:\n\n`yarn add @moebius/http-graceful-shutdown`\n\nOr npm:\n\n`npm i -S @moebius/http-graceful-shutdown`\n\n\n## Usage\n\n### Vanilla Server\n\n```js\nconst http = require('http');  \nconst GracefulShutdownManager = require('@moebius/http-graceful-shutdown').GracefulShutdownManager;\n\n\nconst server = http.createServer(/** … */);\nconst shutdownManager = new GracefulShutdownManager(server);\n\nserver.listen(8080);\n\nprocess.on('SIGTERM', () =\u003e {\n  shutdownManager.terminate(() =\u003e {\n    console.log('Server is gracefully terminated');\n  });\n});\n```\n\n### Express Server\n\n```js\nconst express = require('express');\nconst GracefulShutdownManager = require('@moebius/http-graceful-shutdown').GracefulShutdownManager;\n\n\nconst app = express();\n\nconst server = app.listen(8080);\n\nconst shutdownManager = new GracefulShutdownManager(server);\n\nprocess.on('SIGTERM', () =\u003e {\n  shutdownManager.terminate(() =\u003e {\n    console.log('Server is gracefully terminated');\n  });\n});\n```\n\n## API\n\n### GracefulShutdownManager Class\n\n- `construct (server: http.Server)`\n\n  Creates an instance of `GracefulShutdownManager` class.\n\n  The `server` argument is a Node.js HTTP server instance, i.e. `http.Server`.\n  If you are using Express, you can obtain it like this: `const server = app.listen(/** … */);`\n\n- `terminate(callback: Function)`\n\n  Initiates graceful termination of the server by closing all idle connections first and\n  then by waiting for pending requests to finish. New requests are not accepted after calling this.\n\n\n## Support\n\nIf you like this module please consider to add a star on [GitHub repository][repo-gh].\n\nThank you!\n\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 Slava Fomin II, MOEBIUS FOUNDATION.\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n\n  [repo-gh]: https://github.com/moebiusmlm/http-graceful-shutdown\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-moebius%2Fhttp-graceful-shutdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthe-moebius%2Fhttp-graceful-shutdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthe-moebius%2Fhttp-graceful-shutdown/lists"}