Which is the better practice about Node.js Error Handler

To avoid node/ express server crashing, it is always a good idea to catch the errors. As far as I found, there are three ways to record the error:

  1. throw new Error(err);

  2. logger(err);

  3. res,json(500, err);

Should I use all of them to catch an error, if so, what is the invoking order?

Is it possible to avoid crashing if we just throw the error?

Check out this guy link and learn about error handling

https://www.youtube.com/watch?v=p-2fzgfk9AA

His video is very informative and he explains all different types of error handlings

You can use a package connect-domain.

Here is the example.

http://masashi-k.blogspot.com/2012/12/express3-global-error-handling-domain.html

Or You can use node.js built in uncaught exception event to handle uncaught errors.

//put this code in your server.js

process.on('uncaughtException', function(err) {
     console.log('Caught exception: ' + err);
});