Problem Statement
How do you handle graceful shutdown in Node.js?
Explanation
Graceful shutdown ensures open connections and background tasks finish before exiting. You can listen for signals like SIGINT or SIGTERM and close servers cleanly.
Code Solution
SolutionRead Only
process.on('SIGINT',()=>{
server.close(()=>{
console.log('Server closed gracefully');
process.exit(0);
});
});