8

I see in top of the fs.js there is a process.binding('fs').

https://github.com/nodejs/node/blob/master/lib/fs.js#L10:

const binding = process.binding('fs');

And then, it's used as:

binding.open(pathModule._makeLong(path),
           stringToFlags(flag),
           0o666,
           req);

(In https://github.com/nodejs/node/blob/master/lib/fs.js#L303-L306)

My question is:

  • What does process.binding('fs') mean?
  • What's fs here (We already in fs.js)?
  • Where can I find the source code of binding.open? Is it Javascript code or c/c++ code?
Freewind
  • 177,284
  • 143
  • 381
  • 649

1 Answers1

11
  1. process.binding() is an internal API used by node to get a reference to the various core C++ bindings.
  2. 'fs' in process.binding('fs') is a reference to the C++ binding (src/node_file.cc in the node source tree) for the fs module.
  3. As mentioned, process.binding() references C++ bindings, so in this case binding.open() is exported here and defined here.
mscdex
  • 93,083
  • 13
  • 170
  • 135