Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

19 lines (13 sloc) 1.982 kB

Globals in Node

Node has a number of built-in global identifiers that every Node.js developer should have some familiarity with. Some of these are true globals, being visible everywhere; others exist at the module level, but are inherent to every module, thus being pseudo-globals.

First, let's go through the list of 'true globals':

  • global - The global namespace. Setting a property to this namespace makes it globally visible within the running process.
  • process - Node's built-in process module, which provides interaction with the current Node process. Read More
  • console - Node's built-in console module, which wraps various STDIO functionality in a browser-like way. Read More
  • setTimeout(), clearTimeout(), setInterval(), clearInterval() - The built-in timer functions are globals. Read More

As mentioned above, there are also a number of 'pseudo-globals' included at the module level in every module:

  • module, module.exports, exports - These objects all pertain to Node's module system. Read More
  • __filename - The __filename keyword contains the path of the currently executing file. Note that this is not defined while running the Node REPL.
  • __dirname - Like __filename, the __dirname keyword contains the path to the root directory of the currently executing script. Also not present in the Node REPL.
  • require() - The require() function is a built-in function, exposed per-module, that allows other valid modules to be included. Read More

Much of this functionality can be extremely useful for a Node.js developer's daily life - but at the very least, remember these as bad names to use for your own functions!

Jump to Line
Something went wrong with that request. Please try again.