From d08463a9e3edcb25d877519293b64c550b59c893 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 | 51 +++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/doc/api/globals.md b/doc/api/globals.md index ca96ec4478d6ca..9154e54beb3675 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); // 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