Q57: How do you implement a graceful shutdown in a Node.js server?
Listen for termination signals (SIGTERM, SIGINT), stop accepting new incoming requests using server.close(), complete pending requests, close active database pools, and exit the process.
Key Takeaways
- Intercept process signals like
SIGTERMandSIGINT. - Close server connections and database client pools cleanly before exiting.
Knowledge Check
Which process termination signal is typically sent by orchestrators like Kubernetes to stop a container?