{"id":21511996,"url":"https://github.com/strvcom/heimdall","last_synced_at":"2025-04-09T18:20:51.573Z","repository":{"id":34841080,"uuid":"182252395","full_name":"strvcom/heimdall","owner":"strvcom","description":"The Node.js process lifecycle gatekeeper","archived":false,"fork":false,"pushed_at":"2024-02-25T17:40:13.000Z","size":2108,"stargazers_count":9,"open_issues_count":5,"forks_count":2,"subscribers_count":7,"default_branch":"master","last_synced_at":"2024-04-26T04:03:03.025Z","etag":null,"topics":["nodejs","process","signals"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/strvcom.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}},"created_at":"2019-04-19T11:08:38.000Z","updated_at":"2024-06-20T00:08:59.215Z","dependencies_parsed_at":"2024-02-16T19:28:23.235Z","dependency_job_id":"cb155d1a-8f29-411c-8d94-a4c92bddda73","html_url":"https://github.com/strvcom/heimdall","commit_stats":{"total_commits":106,"total_committers":4,"mean_commits":26.5,"dds":"0.14150943396226412","last_synced_commit":"4e3b67bffa164bbd0cc661e75a5e34a4ee1a8f56"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2Fheimdall","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2Fheimdall/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2Fheimdall/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/strvcom%2Fheimdall/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/strvcom","download_url":"https://codeload.github.com/strvcom/heimdall/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248085388,"owners_count":21045152,"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":["nodejs","process","signals"],"created_at":"2024-11-23T22:24:50.291Z","updated_at":"2025-04-09T18:20:51.551Z","avatar_url":"https://github.com/strvcom.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @strv/heimdall\n\n[![Build Status][ci-badge]][ci-url]\n\n\u003e The process lifecycle gatekeeper.\n\u003e\n\u003e Built with ❤️ at [STRV][strv-home]\n\nHeimdall takes control over the Node.js process' signal handling and provides a simple way to respond to various process lifecycle events.\n\n## Installation\n\n```sh\nnpm i --save @strv/heimdall\n```\n\n## Usage\n\n```js\nimport { heimdall } from '@strv/heimdall'\n// Import something important. Maybe a Koa server? Or Atlas.js instance?\nimport { app } from './app'\n\nheimdall({\n  /**\n   * The execute method is invoked by Heimdall immediately after calling `heimdall()`. You can\n   * start your servers and set up any other important tasks here.\n   * @return    {Promise}\n   */\n  async execute() {\n    // Start whatever you need to start in this process. Whatever you return from this function, you\n    // will receive it in the .exit() method below.\n    return await app.start(process.env.PORT)\n  },\n\n  /**\n   * This method will be invoked by Heimdall when the process receives a `SIGINT` or `SIGTERM`\n   * signal. This method is also invoked when Node.js' event loop will empty and Node determines\n   * that it can safely exit itself.\n   * @return    {Promise}\n   */\n  async exit({ runtime }) {\n    // Stop your servers, close down your open sockets or other activities that might be\n    // keeping the Node process running.\n    await app.stop()\n\n    // runtime is exactly what you returned in .execute(), in this case it is the Koa instance\n    app === runtime\n  },\n\n  /**\n   * This optional method will be invoked by Heimdall when the process receives a second `SIGINT` or\n   * `SIGTERM` signal (ie. the user pressing ctrl+c twice). You can log something to the console or\n   * perform synchronous cleanup, but the Node process will be terminated shortly and any async I/O\n   * operations are not guaranteed to complete in time.\n   * @return    {void}\n   */\n  didReceiveForcequit() {\n    // This is a synchronous method call. Running async I/O operations is not guaranteed to work.\n  },\n\n  /**\n   * This optional method will be used by Heimdall when one of the Delegate's methods throws an\n   * error. Heimdall logs these errors to the stderr output stream but if you implement this method,\n   * it will let you log the error using your logging solution of choice.\n   *\n   * The log should be synchronous as the process will be terminated in the next event loop.\n   */\n  logError(err) {\n    pino.error({ err }, 'heimdall received error')\n  }\n\n  /**\n   * Set this to true to let Heimdall call the exit handler as soon as the execute handler finishes\n   *\n   * This is ideal for one-off scripts, commands or other utilities where you want to do a task and\n   * then let the process exit gracefully.\n   */\n  exitAfterExecute?: false\n})\n```\n\n## License\n\nSee the [LICENSE](LICENSE) file for information.\n\n[strv-home]: https://www.strv.com\n[ci-badge]: https://github.com/strvcom/heimdall/workflows/Continuous%20Integration/badge.svg\n[ci-url]: https://github.com/strvcom/heimdall/actions?query=workflow%3A%22Continuous+Integration%22\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrvcom%2Fheimdall","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstrvcom%2Fheimdall","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstrvcom%2Fheimdall/lists"}