Module exports and exports in Node.js
Module is Javascript object. Exports is its property. Exports is Javascript variable set to module.exports. Node.js will return module.exports to the require function at the end of the file. In a simplified way to view JS file in Node is:
var module = { exports: {} };
var exports = module.exports;
// your code
return module.exports;
If you set a property on exports like exports.a=9; it will also set module.exports.a . This is because, in Javascript objects are passed around as references that is if you set multiple variables to an object they are all the same object i.e. module.exports and exports are same objects. If you set a new variable to exports it will no longer be set to module.exports.
Comments
0 comments
Please Sign in or Create an account to Post Comments