{"id":13464929,"url":"https://github.com/futurestudio/hapi-pulse","last_synced_at":"2025-04-12T19:09:05.434Z","repository":{"id":34186000,"uuid":"127907326","full_name":"futurestudio/hapi-pulse","owner":"futurestudio","description":"hapi plugin that gracefully stops the hapi server (for graceful process reloads, e.g. with PM2)","archived":false,"fork":false,"pushed_at":"2023-07-25T03:27:20.000Z","size":369,"stargazers_count":20,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-26T13:21:15.292Z","etag":null,"topics":["future-studio-university","graceful-shutdown","hapi","hapi-plugin","hapi-pulse","hapi-server","hapijs","pm2","shutdown","signal"],"latest_commit_sha":null,"homepage":"","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/futurestudio.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}},"created_at":"2018-04-03T12:48:34.000Z","updated_at":"2024-01-17T13:52:51.000Z","dependencies_parsed_at":"2024-01-16T05:41:21.408Z","dependency_job_id":"fb9fd460-de22-4fd6-887a-2e8807113e60","html_url":"https://github.com/futurestudio/hapi-pulse","commit_stats":{"total_commits":259,"total_committers":9,"mean_commits":28.77777777777778,"dds":0.6061776061776062,"last_synced_commit":"cd4b88605bd7ef6824f89257712faebef9c2459c"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-pulse","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-pulse/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-pulse/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/futurestudio%2Fhapi-pulse/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/futurestudio","download_url":"https://codeload.github.com/futurestudio/hapi-pulse/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537226,"owners_count":21120716,"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":["future-studio-university","graceful-shutdown","hapi","hapi-plugin","hapi-pulse","hapi-server","hapijs","pm2","shutdown","signal"],"created_at":"2024-07-31T14:00:52.966Z","updated_at":"2025-04-12T19:09:05.406Z","avatar_url":"https://github.com/futurestudio.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"471\" style=\"max-width:100%;\" src=\"https://raw.githubusercontent.com/futurestudio/hapi-pulse/master/media/hapi-pulse.png\" alt=\"hapi-pulse logo\"\u003e\n\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n\n  \u003cp\u003e\n    hapi plugin to gracefully stop your hapi server\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n    \u003ca href=\"#installation\"\u003e\u003cstrong\u003eInstallation\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#usage\"\u003e\u003cstrong\u003eUsage\u003c/strong\u003e\u003c/a\u003e ·\n    \u003ca href=\"#plugin-registration-options\"\u003e\u003cstrong\u003ePlugin Options\u003c/strong\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cbr/\u003e\n  \u003cbr/\u003e\n  \u003cp\u003e\n     \u003ca href=\"https://travis-ci.org/futurestudio/hapi-pulse\"\u003e\u003cimg src=\"https://travis-ci.org/futurestudio/hapi-pulse.svg?branch=master\" alt=\"Build Status\" data-canonical-src=\"https://travis-ci.org/futurestudio/hapi-pulse.svg?branch=master\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://snyk.io/test/github/futurestudio/hapi-pulse\"\u003e\u003cimg src=\"https://snyk.io/test/github/futurestudio/hapi-pulse/badge.svg\" alt=\"Known Vulnerabilities\" data-canonical-src=\"https://snyk.io/test/github/futurestudio/hapi-pulse\" style=\"max-width:100%;\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-pulse\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/hapi-pulse.svg\" alt=\"Latest Version\"\u003e\u003c/a\u003e\n    \u003ca href=\"https://www.npmjs.com/package/hapi-pulse\"\u003e\u003cimg src=\"https://img.shields.io/npm/dm/hapi-pulse.svg\" alt=\"Total downloads\"\u003e\u003c/a\u003e\n  \u003c/p\u003e\n  \u003cp\u003e\n    \u003cem\u003eFollow \u003ca href=\"http://twitter.com/marcuspoehls\"\u003e@marcuspoehls\u003c/a\u003e for updates!\u003c/em\u003e\n  \u003c/p\u003e\n\u003c/div\u003e\n\n------\n\n\u003cp align=\"center\"\u003e\u003csup\u003eThe \u003ca href=\"https://futurestud.io\"\u003eFuture Studio University\u003c/a\u003e supports development of this hapi plugin 🚀\u003c/sup\u003e\n\u003cbr\u003e\u003cb\u003e\nJoin the \u003ca href=\"https://futurestud.io/university\"\u003eFuture Studio University and Skyrocket in Node.js\u003c/a\u003e\u003c/b\u003e\n\u003c/p\u003e\n\n------\n\n\n## Introduction\nA hapi plugin that gracefully stops the hapi server on `SIGINT` and `SIGTERM` and your custom signals.\n\n`hapi-pulse` works great with [**PM2**](https://github.com/Unitech/pm2) and other Node.js process manager to accomplish zero-downtime deployments!\n\nThis serves existing requests before closing the connection and stopping the hapi server process.\nIt uses hapi’s `server.stop()` method to close connections properly.\n\n\n## Requirements\n\u003e **hapi v19 (or later)** and **Node.js v12 (or newer)**\n\nThis plugin requires **hapi v19** (or later) and **Node.js v12 or newer**.\n\n\n### Compatibility\n| Major Release | [hapi.js](https://github.com/hapijs/hapi) version | Node.js version |\n| --- | --- | --- |\n| `v3` | `\u003e=17 hapi` | `\u003e=12` |\n| `v2` | `\u003e=17 hapi` | `\u003e=8` |\n\n\n## Installation\nAdd `hapi-pulse` as a dependency to your project:\n\n```bash\nnpm i hapi-pulse\n```\n\n\n## Usage\nThe most straight forward way to register the `hapi-pulse` plugin:\n\n```js\nawait server.register({\n  plugin: require('hapi-pulse'),\n  options: {\n    // any option that is supported by hapi's \"server.stop()\"\n    timeout: 15000,\n\n    // plugin specific options\n    logger: console,\n    signals: ['SIGINT'],\n    postServerStop: async function () {\n      // await Database.close()\n    }\n  }\n})\n```\n\n\n## Plugin Registration Options\n`hapi-pulse` passes the options through to hapi’s [`server.stop(options)`](https://hapijs.com/api#-await-serverstopoptions).\nCustomize the behavior of `server.stop()`, like the `timeout` before forcefully stopping the process.\n\nAdditionally, you can pass along the following options:\n\n- **logger**: `(Object)`, default: `console` — in case of an error, hapi-pulse logs the error with `logger.error('message', error)`\n- **signals**: `(Array)`, default: `['SIGINT', 'SIGTERM']` — use this `signals` option to customize the events on which hapi-pulse will stop the server\n- **preServerStop**: `(Function)`, default: `Promise.resolve` — an async function that runs before `server.stop()`\n- **postServerStop**: `(Function)`, default: `Promise.resolve` — an async function that runs after `server.stop()`\n- **preShutdown**: `(Function)`, default: `Promise.resolve` — an async function that runs after `postServerStop()` and before `process.exit`\n- **timeout**: `(int)`, default: `5000 (5 seconds)` — the timeout existing connections should be closed until they are forcefully interrupted. This option is passed through to hapi’s `server.stop()`\n\n**Example**\n\n```js\nawait server.register({\n  plugin: require('hapi-pulse'),\n  options: {\n    timeout: 25 * 1000,\n    logger: console,\n    signals: ['SIGINT', 'SIGTERM'],\n    preServerStop: async function () {\n      // this runs before server.stop()\n    },\n    postServerStop: async function () {\n      // this runs after server.stop()\n      // e.g., await Database.close()\n    },\n    preShutdown: async function () {\n      // this runs after postServerStop() and before process.exit\n    }\n  }\n})\n\n// went smooth like chocolate :)\n```\n\n\n## Feature Requests\nDo you miss a feature? Please don’t hesitate to\n[create an issue](https://github.com/futurestudio/hapi-pulse/issues) with a short description of your desired addition to this plugin.\n\n\n## Links \u0026 Resources\n\n- [hapi tutorial series](https://futurestud.io/tutorials/hapi-get-your-server-up-and-running) with 100+ tutorials\n\n\n## Contributing\n\n1.  Create a fork\n2.  Create your feature branch: `git checkout -b my-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 🚀\n\n\n## License\n\nMIT © [Future Studio](https://futurestud.io)\n\n---\n\n\u003e [futurestud.io](https://futurestud.io) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e GitHub [@futurestudio](https://github.com/futurestudio/) \u0026nbsp;\u0026middot;\u0026nbsp;\n\u003e Twitter [@futurestud_io](https://twitter.com/futurestud_io)\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-pulse","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuturestudio%2Fhapi-pulse","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuturestudio%2Fhapi-pulse/lists"}