1

I'm going to deploy a nodejs server(using express) and I wanted to make sure the server restarts if any crashes happen, I searched a bit and discovered PM2, and it seems to be a great tool for that, but I was wondering, is there anyway to call a function/script when a crash happen? To maybe log it in a DB, or notify me with an e-mail.

Maybe I don't even need PM2 for that, I found this in another SO topic

process.on('uncaughtException', function (err) {
  console.error(err);
  console.log("Node NOT Exiting...");
});

Is this a good way of doing it?

And yes, I'm aware of how you can catch express errors with a middleware, and I'm already using it, I just want to make sure that a problem somewhere else doesn't stop my server

Levy Barbosa
  • 342
  • 1
  • 5
  • 13

0 Answers0