{"id":15680202,"url":"https://github.com/sholladay/app-ready","last_synced_at":"2025-08-24T14:21:22.536Z","repository":{"id":57182579,"uuid":"82406480","full_name":"sholladay/app-ready","owner":"sholladay","description":"Support graceful start in your app","archived":false,"fork":false,"pushed_at":"2017-10-23T01:39:11.000Z","size":13,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-27T03:33:46.386Z","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":"2017-02-18T18:14:28.000Z","updated_at":"2019-06-06T15:39:00.000Z","dependencies_parsed_at":"2022-09-11T22:40:28.978Z","dependency_job_id":null,"html_url":"https://github.com/sholladay/app-ready","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fapp-ready","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fapp-ready/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fapp-ready/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sholladay%2Fapp-ready/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sholladay","download_url":"https://codeload.github.com/sholladay/app-ready/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252632327,"owners_count":21779634,"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","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-03T16:40:49.223Z","updated_at":"2025-05-07T20:10:31.957Z","avatar_url":"https://github.com/sholladay.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# app-ready [![Build status for App Ready](https://img.shields.io/circleci/project/sholladay/app-ready/master.svg \"Build Status\")](https://circleci.com/gh/sholladay/app-ready \"Builds\")\n\n\u003e Support [graceful start](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-start) in your app\n\nSignal that your app is ready for use, so a process manager can bring it online at the right time.\n\n## Why?\n\n - Allows any parent process to track async startup.\n - Avoids filesystem polling and \"ready files\".\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 app-ready --save\n```\n\n## Usage\n\nGet it into your program.\n\n```js\nconst appReady = require('app-ready');\n```\n\nTell the parent process that we are ready.\n\n```js\nawait database.connect();\nawait server.listen();\nappReady();\n```\n\n## Use with PM2\n\nTo achieve zero downtime deployments, [PM2](https://github.com/Unitech/pm2) needs to know when your app is ready to use. It tries to be smart and automatically waits for you to call [`server.listen()`](https://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback). However, there are some limitations with this (for more details, see [pm2#2573](https://github.com/Unitech/pm2/issues/2573)).\n\n - If you never actually call `server.listen()`, PM2 won't know what to do and will eventually time out and forcefully restart your app in an ettempt to get it to boot correctly.\n - If you do call `server.listen()`, but your app is not 100% ready at that point, then your app will receive traffic at the wrong time and it might blow up.\n\nThese problems can be fixed by being more explicit. Let's use [graceful start](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-start) and tell PM2 to wait for our signal!\n\n```console\n$ pm2 start app.js --wait-ready --listen-timeout 3000\n```\n\nAbove, `--wait-ready` tells PM2 to ignore `server.listen()` and wait for the more explicit message that `appReady()` sends for you. This allows you to more precisely control when PM2 begins sending traffic to your app.\n\nJust in case something goes wrong, `--listen-timeout` tells PM2 how long it should wait for the ready message before considering this a failed start, in which case it will restart the app and try again.\n\nTo support graceful _stop_, see [handle-quit](https://github.com/sholladay/handle-quit).\n\n## API\n\n### appReady()\n\nIf the process is a child of another Node.js process, sends a [`message` event](https://nodejs.org/api/process.html#process_process_send_message_sendhandle_options_callback) to the parent with a value of `ready`. Otherwise, does nothing.\n\n## Related\n\n - [handle-quit](https://github.com/sholladay/handle-quit) - Support [graceful stop](http://pm2.keymetrics.io/docs/usage/signals-clean-restart/#graceful-stop) in your app\n\n## Contributing\n\nSee our [contributing guidelines](https://github.com/sholladay/app-ready/blob/master/CONTRIBUTING.md \"Guidelines for participating in this project\") for more details.\n\n1. [Fork it](https://github.com/sholladay/app-ready/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/app-ready/compare \"Submit code to this project for review\").\n\n## License\n\n[MPL-2.0](https://github.com/sholladay/app-ready/blob/master/LICENSE \"License for app-ready\") © [Seth Holladay](https://seth-holladay.com \"Author of app-ready\")\n\nGo make something, dang it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsholladay%2Fapp-ready","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsholladay%2Fapp-ready","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsholladay%2Fapp-ready/lists"}