Categories
JavaScript Answers

How to get name and line of calling function in Node.js?

Spread the love

To get name and line of calling function in Node.js, we use the error’s stack property.

For instance, we write

console.log("DEBUG", new Error().stack.split("at ")[1].trim());

to create an Error object and use its stack property to get the name and line of the calling function.

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 *