How to print a stack trace in Node.js?

04/15/2020 07:00:02

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

Answer #1 (602 Votes)

05/29/2010 01:45:02

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!")

Answer #2 (195 Votes)

08/28/2011 00:03:24

Now there's a dedicated function on console for that:

Hack Hex uses Stack Exchance API by the Stack Exchange Inc. to scrape questions/answers under Creative Commons license.