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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With