Categories
JavaScript Answers

How to get the path to the current script with Node.js?

Spread the love

Sometimes, we want to get the path to the current script with Node.js.

In this article, we’ll look at how to get the path to the current script with Node.js.

How to get the path to the current script with Node.js?

To get the path to the current script with Node.js, we can use __dirname .

__dirname returns a string with the path of the current script.

For ES nmodules, we can use import.meta.url instead.

Conclusion

To get the path to the current script with Node.js, we can use __dirname .

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 *