🚀 Graceful Shutdown for Node.js
Tiny and stupid simple dependency-free Node.js library to shutdown gracefully.
Requirements
Installation
NPM
npm install --save @relab/graceful-shutdown
PNPM
npm add @relab/graceful-shutdown
Usage
import { handleShutdown, onShutdown } from './utils/@shutdown'
onShutdown(async () => {
})
handleShutdown()
Custom shutdown timeout
import { handleShutdown, onShutdown } from './utils/@shutdown'
handleShutdown({
timeout: 3000
})
Shutdown callbacks
import { handleShutdown, onShutdown } from './utils/@shutdown'
handleShutdown({
onShutdownStart: () => {
console.log('Shut down requested')
},
onShutdownError: reason => {
console.log(`Shutdown tasks error: ${reason}`)
},
onShutdownComplete: () => {
console.log('Shutdown tasks completed')
},
})
License
Released under MIT by Sergey Zwezdin.