It is known that each module in Node.js is wrapped in a function, where 5 arguments are passed in (i.e. exports
, module
, require
, __filename
, __dirname
) and the module.exports
object is returned.
Since exports
is just an alias for module.exports
, is there a reason why both module and exports are listed as 2 separate arguments? In terms of design, is it simply for the ease of accessing the exports object?
I couldn’t find this question being answered, but I’m happy to be redirected to an existing one.
// function (exports, module, require, __filename, __dirname) {
const a = 1;
console.log(a);
// return module.exports;
// }