{"id":13524925,"url":"https://github.com/fastify/restartable","last_synced_at":"2025-05-16T04:06:32.518Z","repository":{"id":37959751,"uuid":"461189289","full_name":"fastify/restartable","owner":"fastify","description":"Restart Fastify without losing a request","archived":false,"fork":false,"pushed_at":"2025-05-01T12:30:58.000Z","size":111,"stargazers_count":107,"open_issues_count":2,"forks_count":10,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-05-01T13:39:28.617Z","etag":null,"topics":["fastify","fastify-library"],"latest_commit_sha":null,"homepage":"https://npmjs.com/package/@fastify/restartable","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/fastify.png","metadata":{"files":{"readme":"README.md","changelog":null,"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},"funding":{"github":"fastify","open_collective":"fastify"}},"created_at":"2022-02-19T12:45:27.000Z","updated_at":"2025-05-01T12:30:54.000Z","dependencies_parsed_at":"2023-02-06T07:16:42.465Z","dependency_job_id":"0ebb6e0d-3667-45f8-a8c0-95d1c3462f7e","html_url":"https://github.com/fastify/restartable","commit_stats":{"total_commits":81,"total_committers":15,"mean_commits":5.4,"dds":0.5925925925925926,"last_synced_commit":"07b41fce2c43f8cff0b3db83eda112981b99bd7c"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Frestartable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Frestartable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Frestartable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fastify%2Frestartable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fastify","download_url":"https://codeload.github.com/fastify/restartable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254464895,"owners_count":22075570,"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":["fastify","fastify-library"],"created_at":"2024-08-01T06:01:14.645Z","updated_at":"2025-05-16T04:06:32.316Z","avatar_url":"https://github.com/fastify.png","language":"JavaScript","readme":"# @fastify/restartable\n\n[![NPM version](https://img.shields.io/npm/v/@fastify/restartable.svg?style=flat)](https://www.npmjs.com/package/@fastify/restartable)\n[![CI](https://github.com/fastify/restartable/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/fastify/restartable/actions/workflows/ci.yml)\n[![neostandard javascript style](https://img.shields.io/badge/code_style-neostandard-brightgreen?style=flat)](https://github.com/neostandard/neostandard)\n\nRestart Fastify without losing a request.\n\nThis module is useful if you want to compose the\nfastify routes dynamically or you need some remote\nconfig. In case of a change, you can restart Fastify.\n\n## Install\n\n```bash\nnpm i @fastify/restartable\n```\n\n## Usage\n\n```js\nimport { restartable } from '@fastify/restartable'\n\nasync function createApp (fastify, opts) {\n  const app = fastify(opts)\n\n  app.get('/restart', async () =\u003e {\n    await app.restart()\n    return { status: 'ok' }\n  })\n\n  app.addHook('onClose', async () =\u003e {\n    if(!app.closingRestartable) {\n      console.log('closing the app because of restart')\n    }\n    else{\n      console.log('closing the app because server is stopping')\n    }\n  })\n\n  return app\n}\n\nconst app = await restartable(createApp, { logger: true })\nconst host = await app.listen({ port: 3000 })\n\nconsole.log('server listening on', host)\n\n// call restart() if you want to restart\nprocess.on('SIGUSR1', () =\u003e {\n  console.log('Restarting the server')\n  app.restart()\n})\n\nprocess.once('SIGINT', () =\u003e {\n  console.log('Stopping the server')\n  app.close()\n})\n\n```\n\n## Hooks\n\n- `preRestart` - called before creating a new app instance and closing an\nexisting one. The hook is called with the current app instance as an argument.\nUse it to close any resources that you don't want to be shared between the\napp instances.\n\n- `onRestart` - called after the new app instance is created and the old one\nis closed. The hook is called with the new app instance as an argument.\n\n**Example**:\n\n```js\n  async function createApplication (fastify, opts) {\n    console.log('creating new app instance')\n    return fastify(opts)\n  }\n  const app = await restartable(createApplication)\n\n  app.addPreRestartHook(async (app) =\u003e {\n    console.log('preRestart hook called')\n  })\n\n  app.addOnRestartHook(async (app) =\u003e {\n    console.log('onRestart hook called')\n  })\n\n  await app.restart()\n```\n\n**Output**:\n\n```bash\npreRestart hook called\ncreating new app instance\nonRestart hook called\n```\n\n## License\n\nLicensed under [MIT](./LICENSE).\n","funding_links":["https://github.com/sponsors/fastify","https://opencollective.com/fastify"],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Frestartable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffastify%2Frestartable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffastify%2Frestartable/lists"}