Categories
Node.js Quick Tips Quick Tips

How to generate a stack trace in Node.js

< 1 min read

Today I learnt: console.trace() is a thing in Node.js. It prints a stack trace to stderr, along with a message if you pass it one.

Much more elegant than what I’ve been doing to generate stack traces up until now: console.log(new Error().stack)

MDN Web Docs for console.trace()

code

output

/ht @davidbailey00

Original tweet