Chapter 3. Node.js Modules

Before writing Node.js applications, you must learn about Node.js modules and packages. Modules and packages are the building blocks for breaking down your application into smaller pieces.

In this chapter, we will cover the following topics:

  • Defining a module
  • The CommonJS module specification
  • Using ES-2015 modules in Node.js
  • Understanding how Node.js finds modules
  • The npm package management system

So, let's get on with it.

Defining a module

Modules are the basic building block for constructing Node.js applications. A Node.js module encapsulates functions, hiding details inside a well-protected container, and exposing an explicitly declared list of functions.

We have already seen modules in action in the previous chapter. Every ...

Get Node.js Web Development - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.