{"id":22840494,"url":"https://github.com/ridakk/nexit","last_synced_at":"2026-04-28T11:32:24.334Z","repository":{"id":35401118,"uuid":"217467800","full_name":"ridakk/nexit","owner":"ridakk","description":"Tiny dependency free utility to exit NodeJs gracefully","archived":false,"fork":false,"pushed_at":"2023-01-04T23:24:43.000Z","size":442,"stargazers_count":0,"open_issues_count":13,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-02-06T08:46:17.016Z","etag":null,"topics":["exit","graceful","graceful-shutdown","health-check","nodejs","ready-check","uncaught","uncaught-exceptions","zero-dependency"],"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/ridakk.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}},"created_at":"2019-10-25T06:39:07.000Z","updated_at":"2020-10-12T17:54:09.000Z","dependencies_parsed_at":"2023-01-15T20:14:53.114Z","dependency_job_id":null,"html_url":"https://github.com/ridakk/nexit","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridakk%2Fnexit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridakk%2Fnexit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridakk%2Fnexit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ridakk%2Fnexit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ridakk","download_url":"https://codeload.github.com/ridakk/nexit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246417425,"owners_count":20773874,"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":["exit","graceful","graceful-shutdown","health-check","nodejs","ready-check","uncaught","uncaught-exceptions","zero-dependency"],"created_at":"2024-12-13T01:12:12.762Z","updated_at":"2026-04-28T11:32:19.281Z","avatar_url":"https://github.com/ridakk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# nexit\n\n[![Build Status](https://travis-ci.org/ridakk/nexit.svg?branch=master)](https://travis-ci.org/ridakk/nexit)\n[![Coverage Status](https://coveralls.io/repos/github/ridakk/nexit/badge.svg?branch=master)](https://coveralls.io/github/ridakk/nexit?branch=master)\n\n***Zero Dependency*** utility to exit NodeJs gracefully\n\n## Install\n\n```bash\nnpm install nexit\n```\n\n## API\n\nConstructor parameters\n\n| Parameter | Default | Description |\n| ----------- | ----------- | ----------- |\n| options.shutdownDelay | 30000 | shutdown delay(ms) |\n| options.exitDelay | 300 | exit delay(ms) |\n\n## Quick Start\n\n```js\nconst Nexit = require('nexit');\n\nnew Nexit.Nexit();\n```\n\nor\n\n```js\nimport { Nexit } from 'nexit';\n\nnew Nexit();\n```\n\n## Description\n\nThis library aims to delay process exit by a configurable amount of time to let service/traffic orchestrator to stop routing active traffic so that the process can be killed safely.\n\n1. `SIGINT`, `SIGTERM` and `uncaughtException` signals\n2. start a timer with `shutdownDelay` after catching one of the signals above.\n3. fire an event with `NEXIT_SHUTDOWN` to let application know about the state\n\u003e application can use this event for its `healthz` route as below.\n4. once `shutdownDelay` timer is expired, start a new timer with `exitDelay`\n5. fire an event with `NEXIT_EXIT` to let application know about the state\n6. at this point, application may exit on its own at any time if node event loop is fully cleared\n7. once `exitDelay` timer is expired, application will be killed forcefully by `process.exit` command\n\n## Usage\n\nSimple `healthz` route implementation for ExpressJs.\n\n```js\nconst express = require('express');\nconst Nexit = require('nexit');\n\nconst app = express();\n\nconst nexit = new Nexit.Nexit();\nnexit.on(Nexit.NEXIT_SHUTDOWN, (err, signal) =\u003e {\n  console.log(`server is shutting down signal: ${signal}`, err);\n  app.set('isShuttingDown', true);\n});\nnexit.on(Nexit.NEXIT_EXIT, () =\u003e {\n  console.log('server is exiting...');\n});\n\napp.get('/healthz', (req, res) =\u003e {\n  const isShuttingDown = app.get('isShuttingDown');\n\n  if (isShuttingDown) {\n    res.status(503).send({\n      message: 'shutting down',\n    });\n    return;\n  }\n\n  res.status(200).send({\n    message: 'ok',\n  });\n});\n\napp.listen(8080);\n```\n\nSee `./demo` for a working example;\n\n```bash\ncd ./demo\nnpm install\nnode index.js\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridakk%2Fnexit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fridakk%2Fnexit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fridakk%2Fnexit/lists"}