Graceful Shutdown Handler
The Graceful Shutdown Handler ensures that your Express application terminates safely and predictably when the process receives termination signals (like SIGTERM or SIGINT).
Installation Guide
Install the component using the servercn CLI:
npx servercn-cli add shutdown-handlerWhy Graceful Shutdown Matters
When an application is restarted or stopped (e.g., during a deployment or scaling event), it's important to finish current work. Without graceful shutdown:
- Active HTTP requests are abruptly terminated, leading to errors for users.
- Database connections might be left in a "hanging" state.
- Background tasks might be interrupted without saving progress.
Basic Implementation
Usage
Import and apply the shutdown handler in your main entry file (usually server.ts).