# CommonJS Modules — Node.js

Source: https://www.geekswithgeeks.com/en/nodejs/node-commonjs

> require and module.exports — Node's original module system.

## module.exports

Each file is its own module. Expose values with `module.exports`.

```javascript
// math.js
function add(a, b) {
  return a + b;
}

module.exports = { add };
```

## require()

Pull a module in with `require` — Node caches it after the first load.

```javascript
// app.js
const { add } = require("./math");

console.log(add(2, 3));
```

Output:

```
5
```

## Synchronous by nature

`require` loads modules **synchronously** — fine for local files, but that's one reason ES modules were introduced.
