You are previewing Node Web Development.

Node Web Development

Cover of Node Web Development by David Herron Published by Packt Publishing
O'Reilly logo

Chapter 3. Node Modules

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

In this chapter we shall:

  • Learn what a module is
  • Learn about the CommonJS module specification
  • Learn how Node finds modules
  • Learn about the npm package management system

So let's get on with it.

What's a module?

Modules are the basic building block of constructing Node applications. We have already seen modules i n action; every JavaScript file we use in Node is itself a module. It's time to see what they are and how they work.

In the ls.js example in Chapter 2, Setting up Node, we wrote the following code to pull in the fs module, giving us access ...

The best content for your career. Discover unlimited learning on demand for around $1/day.