diff --git a/doc/api/globals.md b/doc/api/globals.md index dceff6e3ae..b91a49798a 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