We only need to know three points to know the difference between exports and module.exports:
1.exports is a reference to the Module.exports point
2.module.exports initial value is an empty object {}, so exports initial value is also {}
3.require () returns module.exports instead of exports
So:
• We pass
var name = ' NSWBMW ';
Exports.name = name;
Exports.sayname =function () {
console.log (name);
}
exports
Assigning a value is actually module.exports
adding two attributes to this empty object, which is equivalent to the following code:
var name = ' NSWBMW ';
Module.exports.name = name;
Module.exports.sayName =function () {
console.log (name);
The above in-depth understanding of node exports and Module.exports difference is small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.