doc: clarify that __dirname is module local
authorJames M Snell <jasnell@gmail.com>
Sat, 2 Apr 2016 06:06:28 +0000 (23:06 -0700)
committerMyles Borins <mborins@us.ibm.com>
Mon, 11 Apr 2016 17:32:01 +0000 (13:32 -0400)
Fixes: https://github.com/nodejs/node/issues/5525
PR-URL: https://github.com/nodejs/node/pull/6018
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Roman Klauke <romaaan.git@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
doc/api/globals.markdown

index 94fc332..1bee7d0 100644 (file)
@@ -30,6 +30,16 @@ console.log(__dirname);
 
 `__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/mj/app`.
+
 ## \_\_filename
 
 <!-- type=var -->