Node.js - Present Working Directory using __dirname

by
Jeremy Canfield |
Updated: July 22 2024
| Node.js articles
__dirname can be used to return your present working directory. For example, let's say you are on a Linux system and you are currently in the /home/john.doe directory.
[john.doe@localhost ~]$ pwd
/home/john.doe
And let's say /home/john.doe/app.js contains the following.
console.log(__dirname);
Running app.js should return the present working directory.
[john.doe@localhost ~]$ node app.js
/home/john.doe
Did you find this article helpful?
If so, consider buying me a coffee over at