You cannot access the multiply function because javascript objects are passed by reference. When you use the line module.exports = {blah}, you create a new object {blah} and set module.exports to point at it. However, exports still points to the old object.
Initially, module.exports and exports point to the same empty object.
So, exports = {} , module.exports = {}. But when you create a new object and have module.exports point at it, Eg:
module.exports = {
sum : function(a,b){
return a+b;
}
};
module.exports will point at the new object, but exports will still point at the old object:
// exports will still point to the old object
console.log(exports) // prints {}
console.log(module.exports) // prints { sum: function() }
Then:
console.log(exports) // prints {}
exports.multiply = function(a,b){
return a*b;
};
console.log(exports) // prints { multiply: function() }
When you import the module, you are returned the value in module.exports, so you won't have access to the multiply function, since that was defined in exports, which references a different object.
If you don't want to worry about this issue, you can just do:
exports = module.exports = {
sum : function(a,b){
return a+b;
}
};
This will make them reference the same object. Hence,
exports.multiply = function(a,b){
return a*b;
};
will work as normal.