0

I use forever to keep a nodejs instance up.

When there is an error, the server stops working and the log shows a javascript exception.
(for example, a get request returns nothing when the server code expected it to).

Is there a way for node to NEVER stop running? To simply "look past" the error?

quelquecosa
  • 890
  • 1
  • 10
  • 24

2 Answers2

1

You should have a look here: Node.js Best Practice Exception Handling

that's the way to handle exceptions:

process.on('uncaughtException', function(err) {
  console.log(err);
})
Community
  • 1
  • 1
Hitmands
  • 13,491
  • 4
  • 34
  • 69
1

The only safe way to prevent Node from ever stopping is to write perfect, bug-free code.

But once you've resigned yourself to the occasional uncaught exception, the safe and recommended approach is to crash and restart with an external monitor.

Unhandled exceptions inherently mean that an application is in an undefined state. Attempting to resume application code without properly recovering from the exception can cause additional unforeseen and unpredictable issues.

-- https://nodejs.org/api/process.html#process_event_uncaughtexception

Emmett
  • 14,035
  • 12
  • 56
  • 81