Throughout the book you’ll have a chance to work with several Node modules, most of them core modules. These modules are included with the Node installation, and incorporated into the application using the global
In this chapter, we’ll explore the concept of the Node module more closely, look at the
require statement in detail, and introduce you to npm, the Node package manager. We’ll also go shopping for some non-core modules that many people believe are essential for any Node application development.
Node’s basic implementation is kept as streamlined as possible. Rather than incorporate every possible component of use directly into Node, developers offer additional functionality via modules.
Node’s module system is patterned after the CommonJS module system, a way of creating modules so that they’re interoperable. The core of the system is a contract that developers adhere to in order to ensure that their modules play well with others.
Among the CommonJS module system requirements implemented with Node are:
Support is included for a
require function that takes the module identifier and returns the exported API.
The module name is a string of characters, and may include forward slashes (for identification of paths).
The module must explicitly export that which is to be exposed outside the module.
Variables are private to the module.
Some Node functionality ...