Bootstrap FreeKB - Node.js - Present Working Directory using __dirname
Node.js - Present Working Directory using __dirname

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 44cd21 in the box below so that we can be sure you are a human.