Globals

Like the Browser, Node.js comes with some practical globals for us to use in our applications.

Common

  • global Think of this as like window but for Node.js. DON'T ABUSE IT!

  • __dirname This global is a String value that points the the directory name of the file it's used in.

  • __filename Like __dirname, it too is relative to the file it's written in. A String value that points the the file name.

  • process A swiss army knife global. An Object that contains all the context you need about the current program being executed. Things from env vars, to what machine you're on.

  • exports module require These globals are used for creating and exposing modules throughout your app. We'll get to modules in a second 🌈

The rest

Depending on what version on Node.js you're running, there are so many more globals. Not as many as the Browser, but enough that you'll probably never use many of them. Check them out here.