# ES Modules in Node — Node.js

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

> The standard import/export syntax, natively supported.

## import / export

Set `"type": "module"` in `package.json`, or use a `.mjs` extension, to use ES module syntax.

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

// app.mjs
import { add } from "./math.mjs";
console.log(add(2, 3));
```

Output:

```
5
```

## CommonJS vs ESM

ESM imports are resolved **statically** and support top-level `await`; CommonJS `require` calls are dynamic and synchronous.
