-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Documentation for __dirname is misleading #5525
Comments
When |
Please re-open, as the documentation is still (or again?) misleading even in v7.2.1: http://web.archive.org/web/20161207142244/https://nodejs.org/api/globals.html . To me it looks like File console.log('b start', __dirname);
module.exports = function () { console.log('b func', __dirname); };
console.log('b done', __dirname); File console.log('a start', __dirname);
var b = require('./b/b.js');
console.log('a has required', __dirname);
b();
console.log('a done', __dirname); Output of
|
"script use" and "script run" have same meaning, how do you think they are different? In your example, all uses of __dirname in b.js occur only when b.js is run. If b.js was not running.... console.log would not be called from b.js. That said, I kindof like your description, but note that its almost there already: "__dirname isn't actually a global but rather local to each module". Local is of course a reference to scope, but that is not as explicit as it could be. Also, resolved is not so obvious in its meaning. Would you care to PR a reword? I think the bigger problem is that the __dirname and __filename docs have diverged, astoundingly, their docs should be almost identical, given that __dirname is path.dirname(__filename)! That they have different verbal gymnastics to describe the same concept should be fixed. |
Thanks for showing me, I totally missed that because I only checked the first paragraph earlier.
You're right, and my earlier example even allowed for a much too naive reading of "use". Here's a better one where none of the scripts mention
People less familiar with closure might really think that some part of bar.js might be running even after the "re:" log call, because they confuse to which point in time the explanation of "currently executing script" applies.
Nope, don't have time to word it as perfectionist as I'd expect for a node PR. ;-) |
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: nodejs#5525 PR-URL: nodejs#10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: nodejs#5525 PR-URL: nodejs#10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
__dirname is path.dirname(__filename), but its docs, specifically the attempt to describe javascript scope in terms of "running" and "executing" had drifted apart. Rework to describe one as a variation of the other, move the example, and just describe the names in terms of the module, and it's local variables rather than the ill defined execution concepts. Fix: #5525 PR-URL: #10527 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
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
and
a.js
requiresb.js
. I runnode a.js
, andb.js
uses its__dirname
, which will refer to theb
subdirectory. The current wording implies that it might actually refer to the directory thata.js
is contained in since that is the "script" that I ran from the command line.The text was updated successfully, but these errors were encountered: