@hypercliq/shutdown-cleanup
Phased graceful shutdown for Node.js — register async cleanup handlers that run in order when your process receives SIGTERM, SIGINT, SIGHUP, or beforeExit.
Quick start
import { registerHandler } from '@hypercliq/shutdown-cleanup'
registerHandler(async (signal) => {
await server.close()
await db.disconnect()
})
Features
- Phased execution — group handlers into numbered phases, run in order
- Signal-specific handlers — attach custom logic to one signal without triggering full shutdown
- Sync and async — both handler types work transparently
- Error strategies —
continue(default) orstopon handler failure - Shutdown timeout — force-exits if cleanup hangs (default 30 s)
- Custom exit codes
- TypeScript declarations included
- ESM-only, Node.js ≥ 22
Installation
npm install @hypercliq/shutdown-cleanup
# or
yarn add @hypercliq/shutdown-cleanup
# or
pnpm add @hypercliq/shutdown-cleanup
Documentation
Full API reference, phased shutdown examples, signal-specific handlers, error strategies, and best practices in the Developer Guide.