Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how is __dirname implemented in Node.js?

I am quite new to Node.js and have come across the "__dirname" and found it to be quite handy for getting the absolute directory path of the script. But I am curious as to how it is implemented, how is it able to understand the directory structure. I have gone through the node js source code but I am not able to find a proper answer.

like image 459
arvind Avatar asked May 10 '26 01:05

arvind


1 Answers

these object are available globally to use in node create a file anywhere in your system with any name suppose app.js and write in that file

 console.log(__dirname);

run it like :-

    node app.js

it will print the path of current directory.

like image 131
mayank Avatar answered May 12 '26 15:05

mayank



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!