How do you do graceful shutdown in Node?

Node.js testing, performance and deployment · Freshers and experienced

Model answer

Listen for SIGTERM and SIGINT, stop accepting new connections with server.close(), let in-flight requests finish, close the database connection, then exit. A timeout forces exit if something hangs. It prevents dropped requests during deploys and restarts.

Learn this topic

Deploy a MERN App to a VPS with pm2, nginx and HTTPS (Let's Encrypt) in the course MERN Stack Full Course: MongoDB, Express, React and Node.js.

Sign in to add your own answer.

More questions