Stack trace nodejs REST API errors

How to show stack trace information when there's an error in an api (written in nodejs)? I used curl to issue a post btw.

I tried node's cli parameter, --stack-trace-limit, but nothing shows up except an unfriendly one liner error message. I could use console.* and debugger lines in the code but it's too time consuming. I tried node-inspector. While it has a nice GUI, it crashes quite. I reckon there has to be an easier way??

Thx. J

Without seeing some code it is hard to answer specifically. However you can also get a stack trace using

var stack = new Error().stack

Useful Modules

  1. Memwatch Useful for outputing heap diffs at various places in your code
  2. node heapdump Allows you to send a kill -SIGUSR2 [pid] to a running node process to generate a heapdump which can then be viewed in the Chrome developer tools by opening up the profiles tab and right clicking in the left pane and choosing Load Profile
  3. Standard v8 debugger run your process with node debug module_name.js Then anywhere you have debugger; statement in your code will cause the debugger to break there
  4. node-webkit-agent A heap and cpu profiling tool that uses the Chrome developer tools interface to profile your node.js application. Debugging is not currently supported but apparently is on the way
  5. Long Stacktraces Sometimes you can get errors that don't have any stack associated with them. I have had this problem with http requests sometimes. Longjohn fixes this problem
  6. node-ofe Automatically generate a heap dump when your app fatally crashes

Code Structure

The way you write asyncronous node.js code can have a big effect on the ease of debugging. Named functions are good, anonymous highly nested functions are bad. Check out http://callbackhell.com/ for a good guide on how to write clean debuggable node.js code