When should I close a NodeJS process?

In the article about node's domains, they say I should not ignore errors -

"The better approach is send an error response to the request that triggered the error, while letting the others finish in their normal time, and stop listening for new requests in that worker."

So my question is, on what types of errors should I close the process:

  • Should I close the process on any error?
  • what If the error is not part of the req/res cycle - should I still close the process? let's say I was doing some callculations on data from the DB, and then when saving it again to the DB, I got an error - should I close the process ?
  • Should I close the process only when I get "uncaught exception" ?

So in general, I would be happy for some general guidelines about when to close a node.js process.

Thanks.

This is something that is primarily about uncaught exceptions.

If your code throws an exception that isn't handled, as a result, some parts of your application may be in an invalid state because the code couldn't finish what it was doing. This is why it's recommended to close/restart processes that do this.

If your process encounters an error which your code handles, then there's no reason to do a restart - you specifically added handling code for the error so that the application does not go into an invalid state and can gracefully handle the error scenario.

So, the answer to the specific question when should you close is when there's an uncaught exception.