8

I have the following code snippet in my node code.

var fs = require('fs');

fs.readdir(__dirname, function (err, files) {
    console.log(files);
});

Why does the variable '__dirname' have double underscores? I know that one underscore is a naming convention for a private/protected variable... but does double underscore mean something more?

jgillich
  • 71,459
  • 6
  • 57
  • 85
Anders Östman
  • 3,702
  • 4
  • 26
  • 48

1 Answers1

5

__dirname and __filename are local to each module but with the particularity that are strings.

http://nodejs.org/docs/latest/api/globals.html

documentation specifies:

__dirname isn't actually a global but rather local to each module.

and normally underscore means private ( In Javascript, what does this underscore mean? )

It can be interpreted as a local private variable to the module.

Audwin Oyong
  • 2,247
  • 3
  • 15
  • 32
Scipion
  • 1,350
  • 1
  • 10
  • 16