{"id":20766995,"url":"https://github.com/binded/gracedown","last_synced_at":"2025-10-26T23:10:34.150Z","repository":{"id":57252970,"uuid":"58241205","full_name":"binded/gracedown","owner":"binded","description":"Collection of consolidated graceful/forceful shutdown procedures for common Node.js libraries.","archived":false,"fork":false,"pushed_at":"2016-05-12T21:36:44.000Z","size":17,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-22T01:46:01.925Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binded.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2016-05-07T00:02:21.000Z","updated_at":"2017-09-17T11:19:35.000Z","dependencies_parsed_at":"2022-08-31T22:20:29.536Z","dependency_job_id":null,"html_url":"https://github.com/binded/gracedown","commit_stats":null,"previous_names":["blockai/gracedown"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fgracedown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fgracedown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fgracedown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fgracedown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/gracedown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243094595,"owners_count":20235531,"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":"2024-11-17T11:27:09.656Z","updated_at":"2025-10-26T23:10:34.045Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gracedown\n\n[![Build Status](https://travis-ci.org/blockai/gracedown.svg?branch=master)](https://travis-ci.org/blockai/gracedown)\n\nCollection of consolidated graceful/forceful shutdown procedures for\ncommon Node.js libraries.\n\nCurrently supports:\n\n- [http server / express](#stophttpserverhttpserver)\n- [knex](#stopknexknex)\n- send PR for more!\n\n## Install\n\n```\nnpm install --save gracedown\n```\n\n## Usage\n\n### gracedown(handlers, [, opts])\n\nReturns a function which can be called to gracefully shutdown your application.\n\nThe returned function doesn't call `process.exit` or output any text by\ndefault, unless `opts.shutdown` is set to true.\n\n- **handlers**: array of [shutdown handlers](#shutdown-handlers)\n- **opts.shutdown**: if true, changes default option values (defaults to `false`)\n- **opts.timeout**: timeout in ms before forceful shutdown (defaults to `10000`)\n- **opts.log**: logging function\n- **opts.logError**: logging function for errors\n- **opts.exit**: exit function\n- **opts.exitError**: exit function on error\n\nDefault values if `shutdown` is `false`:\n\n```javascript\n// where noop = () =\u003e {}\n{\n  timeout: 10000,\n  log: noop,\n  logError: noop,\n  exit: noop,\n  exitError: noop,\n}\n```\n\nDefault values if `shutdown` is `true`:\n\n```javascript\n{\n  timeout: 10000,\n  log: console.log.bind(console),\n  logError: console.error.bind(console),\n  exit: () =\u003e process.exit(),\n  exitError: () =\u003e process.exit(1),\n}\n```\n\n### Shutdown Handlers\n\n**shutdownHandler(opts)**\n\nHandlers are Promise-returning functions which accept the following options object:\n\n- **opts.log** and **opts.logError**: same as above\n- **opts.forceful**: `true` if we want to shutdown as quick as possible (defaults to `false`).\n    For example, the http server handle doesn't wait for connections to\n    close if this is true.\n\nThe following functions return shutdown handlers for common Node.js\nlibraries/modules.\n\n#### stopHttpServer(httpServer)\n\n- **httpServer**: Node.js http server instance\n\n#### stopKnex(knex)\n\n- **knex**: [Knex.js](http://knexjs.org/) object\n\n## Example\n\n```javascript\nimport gracedown, { stopHttpServer } from 'gracedown'\nimport http from 'http'\n\nconst httpServer = http.createServer((req, res) =\u003e res.end('ok'))\nhttpServer.listen()\n\nconst someTimeout = setTimeout(() =\u003e {\n  console.log('timeout called')\n}, 3000)\n\nconst shutdown = gracedown([\n  stopHttpServer(httpServer),\n  // Custom shutdown procedure\n  () =\u003e {\n    clearTimeout(someTimeout)\n  }\n], { timeout: 5000, shutdown: true })\n\nprocess.on('SIGTERM', shutdown)\nprocess.on('SIGINT', shutdown)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fgracedown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Fgracedown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fgracedown/lists"}