Categories
JavaScript Answers

How to print a stack trace in Node.js?

Spread the love

Sometimes, we want to print a stack trace in Node.js.

In this article, we’ll look at how to print a stack trace in Node.js.

How to print a stack trace in Node.js?

To print a stack trace in Node.js, we can get the stack property from the Error instance.

For instance, we write

const {
  stack
} = new Error()
console.log(stack)

to get the stack trace from the stack property of the Error instance.

We can also use console.trace method with no argument to print the stack trace.

Conclusion

To print a stack trace in Node.js, we can get the stack property from the Error instance.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *