# @totalsoft/graceful-shutdown

> Graceful shutdown after intercepting signals and unhandled exceptions

Latest version **2.0.1** (published 2026-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @totalsoft/graceful-shutdown
pnpm add @totalsoft/graceful-shutdown
yarn add @totalsoft/graceful-shutdown
bun add @totalsoft/graceful-shutdown
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; no vulnerabilities; recently updated; high quality score.

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2026-07-08 |
| First published | 2022-09-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 168.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 26 |
| Author | TotalSoft |
| Maintainers | osstotalsoft |
| Keywords | shutdown |

## Links

- npm: https://www.npmjs.com/package/@totalsoft/graceful-shutdown
- Repository: https://github.com/osstotalsoft/rocket-toolkit
- Homepage: https://github.com/osstotalsoft/rocket-toolkit#readme
- Issues: https://github.com/osstotalsoft/rocket-toolkit/issues
- npm.io page: https://npm.io/package/@totalsoft/graceful-shutdown

## Recent versions

- 2.0.1 (latest) — 2026-07-08
- 2.0.0 — 2024-11-06
- 1.1.0 — 2022-09-15

## README

# graceful-shutdown

Graceful shutdown after intercepting signals and unhandled exceptions.

## Installation

```javascript
npm i @totalsoft/graceful-shutdown
```

or

```javascript
yarn add @totalsoft/graceful-shutdown
```

## Usage
```javascript
const { gracefulShutdown } = require('@totalsoft/graceful-shutdown')

async function cleanup() {
  // Perform cleanup before shutdown
}

gracefulShutdown({
  onShutdown: cleanup,
  terminationSignals: ["SIGINT", "SIGTERM", "SIGUSR1", "SIGUSR2"],
  unrecoverableEvents: ["uncaughtException", "unhandledRejection"],
  logger: console,
  timeout: 5000
})
```
## Options

``` javascript
export interface GracefulShutdownOptions {
  // Set an async handler to be called at shutdown
  onShutdown?: (_: any) => Promise<void>

  // Set a timeout in milliseconds to wait for graceful shutdown.
  timeout?: number

  // A list of signals that trigger shutdown (eg. SIGINT, SIGTERM).
  terminationSignals?: string[]

  // A list of process events that trigger shutdown (eg. `unrecoverableException`)
  unrecoverableEvents?: string[]

  // A logger for shutdown events
  logger?: Logger
}
```

---
_Source: https://npm.io/package/@totalsoft/graceful-shutdown · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
