Difference between exports and module.exports

Dhanush N
2 min readNov 13, 2022

The module represents the current module in the plain Javascript object.

Exports is a plain JavaScript variable. Module is a plain javascript object which has the exports property

From one module to another, when we want to export a single class, variable, or function, we use modules. exports.

From one module to another, when we want to export multiple variables or functions, we use exports.

```javascript
var module = { exports: { value1: 10 , value2: 20 } };
var exports = module.exports;

return module.exports;
```

In the above example, we have assigned multiple values to the same object.

module.exports.value1 returns 10 and module.exports.value2 returns 20

```javascript
var module = { exports: 10 } };
var exports = module.exports;

return module.exports;
```

In the preceding example, exports is set to a value that results in modules.exports are no longer the same object.

module.exports returns 10

--

--

Dhanush N
Dhanush N

Written by Dhanush N

Engineer, Chess enthusiast & Tech tinkerer. I build, break and hack systems while exploring the art of problem-solving. 🔗 https://www.youtube.com/@dhanushnehru

No responses yet