{"id":15684903,"url":"https://github.com/sholladay/handle-quit","last_synced_at":"2026-07-18T15:09:09.166Z","repository":{"id":57260503,"uuid":"69147428","full_name":"sholladay/handle-quit","owner":"sholladay","description":"Support graceful stop in your app","archived":false,"fork":false,"pushed_at":"2019-12-31T04:51:49.000Z","size":23,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-27T06:44:04.056Z","etag":null,"topics":["deployment","pm2","reload","server","zero-downtime"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sholladay.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-09-25T06:20:42.000Z","updated_at":"2021-10-23T20:13:15.000Z","dependencies_parsed_at":"2022-08-25T05:02:14.629Z","dependency_job_id":null,"html_url":"https://github.com/sholladay/handle-quit","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/sholladay/handle-quit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fhandle-quit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fhandle-quit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fhandle-quit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fhandle-quit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sholladay","download_url":"https://codeload.github.com/sholladay/handle-quit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fhandle-quit/sbom","scorecard":{"id":820494,"data":{"date":"2025-08-11","repo":{"name":"github.com/sholladay/handle-quit","commit":"7fbca6e9f63640e31291383481aac073fe0a2f9e"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"SAST","score":0,"reason":"no SAST tool detected","details":["Warn: no pull requests merged into dev branch"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Code-Review","score":0,"reason":"Found 0/17 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: Mozilla Public License 2.0: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}}]},"last_synced_at":"2025-08-23T15:23:25.049Z","repository_id":57260503,"created_at":"2025-08-23T15:23:25.050Z","updated_at":"2025-08-23T15:23:25.050Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35621281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-18T02:00:07.223Z","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":["deployment","pm2","reload","server","zero-downtime"],"created_at":"2024-10-03T17:22:21.355Z","updated_at":"2026-07-18T15:09:09.120Z","avatar_url":"https://github.com/sholladay.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# handle-quit [![Build status for Handle Quit](https://travis-ci.com/sholladay/handle-quit.svg?branch=master \"Build Status\")](https://travis-ci.com/sholladay/handle-quit \"Builds\")\n\n\u003e Support [graceful stop](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-stop) in your app\n\nRespond to shutdown signals, so a process manager can reload your app without dropping any connections.\n\n## Why?\n\n - Friendly to your users.\n - Easy to use and reason about.\n - Helps you do easy [zero downtime](https://futurestud.io/tutorials/pm2-cluster-mode-and-zero-downtime-restarts#zerodowntimedeployments) deployments.\n\n## Install\n\n```sh\nnpm install handle-quit --save\n```\n\n## Usage\n\nGet it into your program.\n\n```js\nconst handleQuit = require('handle-quit');\n```\n\nMake sure your program shuts down gracefully or quickly, as necessary.\n\n```js\nhandleQuit(() =\u003e {\n    server.close();\n});\n```\n\nNote that calling [`process.exit()`](https://nodejs.org/api/process.html#process_process_exit_code) is discouraged. Instead, you should close any server and database connections and let Node exit on its own, which it does automatically when it has no more work left to do.\n\nIf you are worried about the process hanging and never cleanly exiting, you are encouraged to use your framework's [stop timeout](https://hapi.dev/api/#server.stop()).\n\n## Use with PM2\n\nTo achieve zero downtime deployments, [PM2](https://github.com/Unitech/pm2) needs to shutdown your app without dropping any connections. It sends a [`SIGINT` signal](https://nodejs.org/api/process.html#process_signal_events) to trigger the shutdown process. However, by default, Node reacts to this by exiting immediately, and thus in-progress connections may be dropped.\n\nThese problems can be fixed by using `handleQuit()` in the main entry of your CLI or server, as shown above, to override the default `SIGINT` behavior and deny _new_ connections on the first `SIGINT`, while allowing any in-progress connections to finish. This is known as [graceful stop](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-stop).\n\nPM2 waits for apps that gracefully stop to quit before replacing them with a new deployment when using `pm2 reload`.\n\n```console\n$ pm2 start app.js --kill-timeout 6000\n```\n\nJust in case something goes wrong, `--kill-timeout` tells PM2 how long it should wait for the process to exit before considering the process hung / frozen, in which case it will force kill the process. You should ensure that `--kill-timeout` is greater than or equal to any stop timeouts used in your app.\n\nTo support graceful _start_, see [app-ready](https://github.com/sholladay/app-ready).\n\n## API\n\n### handleQuit(listener)\n\nListens for [POSIX signals](https://en.wikipedia.org/wiki/Unix_signal#POSIX_signals) (`SIGINT`and `SIGTERM`) and calls the `listener` function on the first signal to perform a graceful shutdown. Calls [`process.exit()`](https://nodejs.org/api/process.html#process_process_exit_code) with an appropriate error code on any further signals that are received to perform an ungraceful shutdown. Relevant messages are also printed to the console.\n\n#### listener\n\nType: `function`\n\nA function that will gracefully shutdown your program. A common example is [Server#close()](https://nodejs.org/api/http.html#http_server_close_callback).\n\n## Related\n\n - [app-ready](https://github.com/sholladay/app-ready) - Support [graceful start](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-start) in your app\n\n## Contributing\n\nSee our [contributing guidelines](https://github.com/sholladay/handle-quit/blob/master/CONTRIBUTING.md \"Guidelines for participating in this project\") for more details.\n\n1. [Fork it](https://github.com/sholladay/handle-quit/fork).\n2. Make a feature branch: `git checkout -b my-new-feature`\n3. Commit your changes: `git commit -am 'Add some feature'`\n4. Push to the branch: `git push origin my-new-feature`\n5. [Submit a pull request](https://github.com/sholladay/handle-quit/compare \"Submit code to this project for review\").\n\n## License\n\n[MPL-2.0](https://github.com/sholladay/handle-quit/blob/master/LICENSE \"License for handle-quit\") © [Seth Holladay](https://seth-holladay.com \"Author of handle-quit\")\n\nGo make something, dang it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsholladay%2Fhandle-quit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsholladay%2Fhandle-quit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsholladay%2Fhandle-quit/lists"}