exports vs module.exports in Node.js

twitter logo github logo ・1 min read

exports.id = 1; //this is ok

exports = {id: 1}; //this is not ok

module.exports = {id: 1}; //this is ok


exports is simply a variable reference to module.exports. So we can change the properties of the exports object, but if we change the whole object, it would no longer be a reference to module.exports

twitter logo DISCUSS (2)
markdown guide

Node supports ECMAScript Modules also, but they are currently experimental.
To enable them, add --experimental-modules for node.

Classic DEV Post from May 11

Handling Array Duplicates Can Be Tricky

Handling Array Duplicates Can Be Tricky

Sherin Binu profile image
JavaScript Developer

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️