What are Global objects in Node.js?

 Node.js has some Global objects which are available in all modules. Some of these objects are not actually in global scope but in the module scope.

  • __dirname: The directory name of the current module. This the same as the path.dirname() of the __filename.
  • __filename: The file name of the current module. This is the resolved absolute path of the current module file.
  • exports: A reference to the module.exports that is shorter to type. exports is not actually a global but rather local to each module.
  • require: To require modules. require is not actually a global but rather local to each module.

Comments

Popular posts from this blog

What test framework did you use to test your nodejs applications

What is V8 Engine? What is the relationship between Node.js and V8?