{"id":28684914,"url":"https://github.com/node-modules/graceful","last_synced_at":"2025-06-14T03:07:50.914Z","repository":{"id":7986442,"uuid":"9391533","full_name":"node-modules/graceful","owner":"node-modules","description":"Graceful exit when `uncaughtException` emit, base on `process.on('uncaughtException')`.","archived":false,"fork":false,"pushed_at":"2024-12-15T08:45:01.000Z","size":151,"stargazers_count":249,"open_issues_count":0,"forks_count":13,"subscribers_count":20,"default_branch":"master","last_synced_at":"2025-05-28T14:54:08.883Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/node-modules.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-04-12T10:03:54.000Z","updated_at":"2024-12-15T08:45:03.000Z","dependencies_parsed_at":"2023-01-13T14:35:41.363Z","dependency_job_id":null,"html_url":"https://github.com/node-modules/graceful","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/node-modules/graceful","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fgraceful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fgraceful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fgraceful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fgraceful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/node-modules","download_url":"https://codeload.github.com/node-modules/graceful/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/node-modules%2Fgraceful/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259752078,"owners_count":22905972,"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":[],"created_at":"2025-06-14T03:07:43.973Z","updated_at":"2025-06-14T03:07:50.906Z","avatar_url":"https://github.com/node-modules.png","language":"TypeScript","readme":"# graceful\n\n[![NPM version][npm-image]][npm-url]\n[![Test coverage][cov-image]][cov-url]\n[![npm download][download-image]][download-url]\n[![Node.js Version](https://img.shields.io/node/v/graceful.svg?style=flat)](https://nodejs.org/en/download/)\n\n[npm-image]: https://img.shields.io/npm/v/graceful.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/graceful\n[cov-image]: https://codecov.io/github/node-modules/graceful/coverage.svg?branch=master\n[cov-url]: https://codecov.io/github/node-modules/graceful?branch=master\n[download-image]: https://img.shields.io/npm/dm/graceful.svg?style=flat-square\n[download-url]: https://npmjs.org/package/graceful\n\nGraceful exit when `uncaughtException` emit, base on `process.on('uncaughtException')`.\n\n## Why we should use this module\n\nIt's the best way to handle `uncaughtException` on current situations.\n\n* [Node.js 异步异常的处理与domain模块解析](http://deadhorse.me/nodejs/2013/04/13/exception_and_domain.html)\n\n## Install\n\n```bash\nnpm install graceful\n```\n\n## Usage\n\nPlease see [express_with_cluster](https://github.com/node-modules/graceful/tree/master/example/express_with_cluster) example.\n\nThis below code just for dev demo, don't use it on production env:\n\n```js\nconst express = require('express');\nconst { graceful } = require('graceful');\n\nconst app = express()\n.use()\n.use(function(req, res){\n  if (Math.random() \u003e 0.5) {\n    foo.bar();\n  }\n  setTimeout(function() {\n    if (Math.random() \u003e 0.5) {\n      throw new Error('Asynchronous error from timeout');\n    } else {\n      res.end('Hello from Connect!');\n    }\n  }, 100);\n  setTimeout(function() {\n    if (Math.random() \u003e 0.5) {\n      throw new Error('Mock second error');\n    }\n  }, 200);\n})\n.use(function(err, req, res, next) {\n  res.end(err.message);\n});\n\nconst server = app.listen(1984);\n\ngraceful({\n  servers: [server],\n  killTimeout: '30s',\n});\n```\n\nIf you have multi servers on one process, you just add them to `server`:\n\n```js\ngraceful({\n  servers: [server1, server2, restapi],\n  killTimeout: '15s',\n});\n```\n\n### ESM and TypeScript\n\n```ts\nimport { graceful } from 'graceful';\n```\n\n## Contributors\n\n[![Contributors](https://contrib.rocks/image?repo=node-modules/graceful)](https://github.com/node-modules/graceful/graphs/contributors)\n\nMade with [contributors-img](https://contrib.rocks).\n\n## License\n\n[MIT](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fgraceful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnode-modules%2Fgraceful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnode-modules%2Fgraceful/lists"}