Chapter 6: Creating and Using Node.js Modules
Modules are at the heart of Node.js. They correspond to JavaScript files and can be used in our applications. A program for the Node.js server will consist of a set of modules, that is, JavaScript files.
There are three kinds of modules:
- Modules that we write ourselves for our applications.
- Modules internal to Node.js and usable directly.
- Modules that can be downloaded from the internet using a utility called
npm
(npm stands for Node.js package manager). Thisnpm
utility is installed with Node.js itself.
In this chapter, we will learn how to create and use these different types of modules.
Regardless of the type of modules used, the require(moduleName)
instruction (see below) allows the module called moduleName
to be included in the current file. The functionalities of the module will then be accessible.
Here are the topics covered in this chapter:
- Using our own modules
- Using internal Node.js...