node-last-wish
v1.0.2
Published
Graceful shutdown handlers for NestJS — catches uncaughtException, unhandledRejection, and SIGTERM
Maintainers
Readme
node-last-wish
A tiny NestJS utility that registers process signal handlers for graceful shutdown.
Install
npm install node-last-wishRequires @nestjs/common ≥ 9 as a peer dependency.
Usage
import { registerCrashHandlers } from 'node-last-wish';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
registerCrashHandlers(app, {
onShutdown: async () => {
// close DB connections, flush logs, etc.
},
});
}
bootstrap();API
registerCrashHandlers(app, opts?)
Registers handlers for uncaughtException, unhandledRejection, and SIGTERM.
On any of these events the process will:
- Run the optional
onShutdownhook. - Close the NestJS application (
app.close()). - Exit with code
1(errors) or0(SIGTERM).
| Parameter | Type | Description |
|---|---|---|
| app | INestApplication | The NestJS application instance. |
| opts.logger | { error(...) } | Custom logger. Defaults to console. |
| opts.onShutdown | () => Promise<void> | Optional cleanup hook run before closing the app. |
Build
npm run build