2

How can I get error reporting in Node? I am running v0.6.15 (used simple osx install DMG) and whenever there is an error, say I try to use a undefined variable, the process just stops with no indication as to why.

I guess im looking for the node version of PHP's error_reporting(E_ALL);

Any suggestions?

==EDIT==

Weird... Ok... So I noticed that I gets errors just fine in the file I run, but not in the ones I "require"

The file I am running simply has this code

process.on('uncaughtException', function(err) {
  console.log(err);
});

var ImageProcessor = require('./ImageProcessor').ImageProcessor;
var imageProcessor = new ImageProcessor();

imageProcessor.imageRequestEnd();

The imageProcessor is a mootools class if that matters but isnt using anything else that special.

4
  • How are you running Node? I've never seen this behavior, and suspect you're running it with some script that is catching all of the output. Commented Apr 26, 2012 at 17:18
  • That's not what happens when I run node on osx... Commented Apr 26, 2012 at 17:21
  • Just opening it straight in terminal $ node file.js Commented Apr 26, 2012 at 18:20
  • See my answer here: stackoverflow.com/questions/10122245/…. Commented Apr 28, 2012 at 16:43

1 Answer 1

2

While I agree with @Brad that I've never seen such behavior, in general, if you're debugging a NodeJS program and want to know what's causing it to be killed, you can use a construct like this:

process.on('uncaughtException', function(err) {
  console.log(err);
});

in your script.

Note that many people argue that you shouldn't use such a construct in production, since an uncaught exception often indicates that you've encountered an error so severe and unexpected that the only way to recover is to restart. This might or might not be true for your particular application; in any case, this can be useful to debug with.

However, like @Brad indicates, the most likely reason why you're not seeing anything is that console output is being redirected somehow. Try running without using "forever", "supervisor", "screen", or whatever other process wrapper you're using.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.