Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capture node.js crash reason

Tags:

node.js

I have a script written in node.js, it uses 'net' library and communicates with distant service over tcp. This script is started using 'node script.js >> log.txt' command and everything in that script that is logged using console.log() function gets written to log.txt but sometimes script dies and I cannot find a reason and nothing gets logged in log.txt around the time script crashed.

How can I capture crash reason?

like image 299
dfilkovi Avatar asked Apr 12 '12 11:04

dfilkovi


1 Answers

Couldn't you listen to uncaughtException event. Something along the lines of =>

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

P.S: after that you are adviced to restart process according to this article from Felix Geisendörfer

like image 158
Alfred Avatar answered Oct 20 '22 00:10

Alfred