Modules

Learn how modules work in Node.js.

What is a module?

Let’s explore what a module is in the context of Node.js.

Each separate file is treated as a module in Node.js. The most common use of modules is to use code or functions across different modules. This allows us to keep our code organized, as each module can serve a specific purpose. This may seem like a circular argument; let’s see what we mean by this in the code widget below. Be sure to go through all three files.

Get hands-on with 1200+ tech skills courses.