How do I send an email for every error that occurs in Node.js? How do I send an email for every error that occurs in Node.js? express express

How do I send an email for every error that occurs in Node.js?


You could replace nodes global console.error() function with one implementation sending emails:

console.error = function(msg) {  // send email  // ...  // additionaly log  process.stderr.write(msg);};

Then every call in every library made to console.error() would call your specific implementation send out mails ;)


Since all log entries are stored in a limited number of log files, in stead of trying to intercept all possible error events, why not just set up a file change monitor and have the new lines mailed to you? That way you can also schedule intervals with summary log entries of the last hour/day/... which will be a lot easier to go through, compared to opening separate mails.