Globals
The Node.js execution context contains a few global variables and functions that can be used from anywhere in any script. The most widely used of all is the require
function, since it is the function that helps you load other modules and access the non-global functions, classes, and variables that are available from the Node.js APIs.
You must have noticed this function being used in the previous chapter when we loaded the commander
module from the package you installed in your application:
const program = require('commander');
It receives one parameter, which is a string representing the ID of the module you want to load, and returns the module's content. Internal modules, such as the ones we will discuss in this chapter, and the modules that are loaded from packages and installed by npm, are identified directly by their names, such as commander, fs, and http. In Chapter 5, Modular JavaScript, you will see how to create your own modules and how to use...