From dd97788d35dc73a62b3aa8fb2986f2b80f6e85ba Mon Sep 17 00:00:00 2001 From: Sam Roberts Date: Thu, 29 Dec 2016 14:11:02 -0800 Subject: [PATCH] doc: unify dirname and filename description __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: https://github.com/nodejs/node/issues/5525 PR-URL: https://github.com/nodejs/node/pull/10527 Reviewed-By: James M Snell Reviewed-By: Gibson Fahnestock --- doc/api/globals.md | 55 ++++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index dceff6e3ae7ccc..b91a49798a41a6 100644 --- a/doc/api/globals.md +++ b/doc/api/globals.md @@ -29,27 +29,20 @@ added: v0.1.27 * {String} -The name of the directory that the currently executing script resides in. +The directory name of the current module. This the same as the +[`path.dirname()`][] of the [`__filename`][]. + +`__dirname` isn't actually a global but rather local to each module. Example: running `node example.js` from `/Users/mjr` ```js console.log(__dirname); -// /Users/mjr +// Prints: /Users/mjr +console.log(path.dirname(__filename)); +// Prints: /Users/mjr ``` -`__dirname` isn't actually a global but rather local to each module. - -For instance, given two modules: `a` and `b`, where `b` is a dependency of -`a` and there is a directory structure of: - -* `/Users/mjr/app/a.js` -* `/Users/mjr/app/node_modules/b/b.js` - -References to `__dirname` within `b.js` will return -`/Users/mjr/app/node_modules/b` while references to `__dirname` within `a.js` -will return `/Users/mjr/app`. - ## \_\_filename