How to print a stack trace in Node.js?

mike.toString picture mike.toString · May 27, 2010 · Viewed 251.3k times · Source

Does anyone know how to print a stack trace in Node.js?

Answer

isaacs picture isaacs · May 28, 2010

Any Error object has a stack member that traps the point at which it was constructed.

var stack = new Error().stack
console.log( stack )

or more simply:

console.trace("Here I am!")