exports.id = 1; //this is ok
exports = {id: 1}; //this is not ok
module.exports = {id: 1}; //this is ok
WHY?
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
Top comments (2)
Well, that was short and sweet. 👌
Node supports ECMAScript Modules also, but they are currently experimental.
To enable them, add --experimental-modules for node.