Graceful shutdown nodejs

Nodejs has a process.on exit event, allowing it to do something before the server shutdown.
However this doesnt work in replit. Is there anyway to do this?

Hi @farmerdev8, this is actually possible in Replit.
You can listen for the exit event and execute a function before the server stops by using the below code:

process.on("exit", () => {
  console.log("Server stopped");
});
3 Likes

It doesnt work if you stop the project

1 Like