Closed
Description
The documentation for __dirname
states that it gives "The name of the directory that the currently executing script resides in."
This may be taken to imply that __dirname
always refers to the path of the module that was invoked as a script from the command line. However, it actually always produces the path of the current module, no matter where it was required from.
Just to clarify: assume I have modules
a.js
b/b.js
and a.js
requires b.js
. I run node a.js
, and b.js
uses its __dirname
, which will refer to the b
subdirectory. The current wording implies that it might actually refer to the directory that a.js
is contained in since that is the "script" that I ran from the command line.