I have been reading about Node's require
and how its exports
is automatically overridden when a module.exports
has data or functionality declared within it. So let me see if I understand correctly: anything that I put in exports will be included in files which require the file.
I have inherited some node files, one main file with heaps of require
s, and each required file with the structure:
var obj = {};
obj.prop1 = "some value1";
obj.prop2 = "some value2";
module.exports = exports = obj;
Is this a standard way of exporting data in a required file? Is it sensible to a)declare this (seemingly redundant obj
)? ,b)if no functionality is being assigned to either exports
or module.exports
, why do they both need to be pointed at obj
? c)what is the purpose of this middle-level exports
if it can be overridden? What is the use case for both of these objects?