---
title: "What is the difference between module.exports and export in Node.js?"
description: "module.exports and require are CommonJS; export and import are ES modules. Learn how Node picks one and how to mix them."
url: "https://bugsee.com/answers/nodejs/module-exports-vs-esm/"
---

# What is the difference between module.exports and export in Node.js?

`module.exports` with `require()` is CommonJS, Node's original format. `export` with `import` is the standard ES module format. A file is one or the other, decided by its extension or package.json.

```js
// CommonJS (.cjs, or .js without "type": "module")
const add = (a, b) => a + b;
module.exports = { add };
const { add } = require("./math");

// ES modules (.mjs, or .js with "type": "module")
export const add = (a, b) => a + b;
import { add } from "./math.js";
```

- ES modules need file extensions in relative imports and support top-level await.
- An ES module can import a CommonJS package, but a CommonJS file cannot use `import` statements; use dynamic `import()` instead.
- Recent Node.js versions can also `require()` many ES modules, but check your target version.

## Related questions

- [How do you fix "Error: Cannot find module" in Node.js?](https://bugsee.com/answers/nodejs/fix-cannot-find-module/)
