This question nearly half a year to see three times, has been a bit of a daze, today look at park and some stack above the information finally is understood point, first record a bit lest forget.
Plain English: exports is just a reference to Module.exports, they all point to the same address in memory.
When node loads the module, each module defaults to a modules object that has a property exports; The initial value is an empty object {}, which can be thought of as the object that the module.exports eventually points to.
--so how to understand exports is just a module.exports reference. You can see that.
var module.exports={}, exports=module.exports; //此时exports 和module.exports指向内存中同一块区域 //我们导出一个函数当使用exports的时候.像这样: exports=function(){ console.log(‘export function‘); } //此时 exports指向的已经是内存中另一块区域了,它已经和module.exports={},赋值的对象没有任何关系,此时他们关系如此密切的两个好基友再无瓜葛。我们使用require()然后调用会报错。 //这种情况导出就可以工作很好理解,就是给最初的对象增加了一个属性sayHello而已. exports.sayHello=function(){ console.log(‘hello‘); }
In fact, it is similar to the reference type assignment and modification in Java.
In StackOverflow see the explanation of the Special 6 please see:
var module = { exports: {} };var exports = module.exports;// your codereturn module.exports;
For reference, please click:
Https://cnodejs.org/topic/5231a630101e574521e45ef8
Difference between module.exports and exports
The difference between module.exports and exports