{"id":25969411,"url":"https://github.com/thesephi/gracefulize","last_synced_at":"2025-10-26T11:43:30.224Z","repository":{"id":68601859,"uuid":"242613936","full_name":"Thesephi/gracefulize","owner":"Thesephi","description":"A lightweight server-side Node.js module that helps properly exit a Node.js process hosting a native Node.js HTTP server","archived":false,"fork":false,"pushed_at":"2020-07-27T07:35:15.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-03T01:32:33.592Z","etag":null,"topics":["handle-resource","helper-tool","server-side"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gracefulize","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Thesephi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","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":"2020-02-24T00:24:20.000Z","updated_at":"2020-07-27T07:35:17.000Z","dependencies_parsed_at":"2023-02-21T09:46:02.094Z","dependency_job_id":null,"html_url":"https://github.com/Thesephi/gracefulize","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Thesephi/gracefulize","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thesephi%2Fgracefulize","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thesephi%2Fgracefulize/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thesephi%2Fgracefulize/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thesephi%2Fgracefulize/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Thesephi","download_url":"https://codeload.github.com/Thesephi/gracefulize/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Thesephi%2Fgracefulize/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":281099963,"owners_count":26443537,"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-26T02:00:06.575Z","response_time":61,"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":["handle-resource","helper-tool","server-side"],"created_at":"2025-03-04T22:48:06.684Z","updated_at":"2025-10-26T11:43:30.219Z","avatar_url":"https://github.com/Thesephi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gracefulize\n\n# Why\n\nA Node.js HTTP server object, once listening on a handle (e.g. a port number),\nis expected to take that \"handle resource\" for itself until it is closed.\n\nExcept when it doesn't.\n\nSay you have a Node.js HTTP server in your `server.js` file, then start it, then\nstop it with `Ctrl + C`, that HTTP server can be killed together with the\nhost process (the `server.js` process itself), but sometimes it doesn't cleanly\nrelease the aforementioned \"handle resource\". In my experience, most times it\ndoes, but it's plain annoying when it doesn't, e.g. when the resource is a unix-\nsocket.\n\nWhile there are \"scientific\" explanations for all this (when it does, and when\nnot), they are beyond the scope of this document, the purpose of which is to\nexplain why this module exists \u0026 how it should be used.\n\nWhat this helper module does is to ensure when the main Node.js process terminates,\n(e.g. on `SIGINT`), it first politely asks the Node.js HTTP server to peacefully\nshutdown, then it waits until the Node.js HTTP server has properly done so before\nallowing the main Node.js process to finally terminate.\n\nHowever, if the Node.js HTTP server fails to cooperate politely (e.g. it hangs\ntrying to serve some unresponsive client, or deal with a cyclic I/O operation -\nyou name it), then the main Node.js process can still be \"coldly\" terminated by\nsending subsequent `SIGINT` signals to it.\n\nHopefully this module provides an acceptable middle ground to properly exit a Node.js\nprocess parenting a Node.js HTTP server. If you find a use case where this module\nis inappropriate, please raise an issue so we could improve this documentation\naccordingly.\n\n# How\n\nIf you already have done something like this before:\n```javascript\nlet express = require('express');\nlet myServer = express.listen(3000, () =\u003e {\n  console.log('server started at port 3000');\n});\n```\n\nThen you only need to add 1 additional line now:\n```javascript\nlet express = require('express');\nlet myServer = express.listen(3000, () =\u003e {\n  console.log('server started at port 3000');\n});\n// the following line is new\nrequire('gracefulize')(myServer);\n```\n\nPlease note that the above example uses `ExpressJS`, but it is essentially the\nsame for `Koa` or any other `Node.js`-based HTTP server.\n\n# Do I need this?\n\n- If you have _never_ implemented anything to ensure a graceful shutdown of your\nNode.js HTTP server for your server app before, then yes\n- Otherwise, probably not\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesephi%2Fgracefulize","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesephi%2Fgracefulize","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesephi%2Fgracefulize/lists"}