I am leaning node js as a beginner.Why we use __dirname in node js when we are reading or writing a file.what is the output of __dirname.
Asked
Active
Viewed 950 times
0
-
Possible duplicate of [What is the difference between \_\_dirname and ./ in node.js?](http://stackoverflow.com/questions/8131344/what-is-the-difference-between-dirname-and-in-node-js) – Marc Scheib May 17 '17 at 17:53
1 Answers
0
__dirname
simply returns the directory you are in. We use it when a function requires an absolute path as a parameter (for example express.static()
requires an absolute path).
We can't always use relative paths, and we just can't count on the fact that our program is always going to be executed from the same location in our computer, so it's basically an equivalent to UNIX's pwd
command.

Corrado
- 645
- 1
- 6
- 16