Looking at a random source file of the express
framework for NodeJS
, there are two lines of the code that I do not understand (these lines of code are typical of almost all NodeJS files).
/**
* Expose `Router` constructor.
*/
exports = module.exports = Router;
and
/**
* Expose HTTP methods.
*/
var methods = exports.methods = require('./methods');
I understand that the first piece of code allows the rest of the functions in the file to be exposed to the NodeJS app, but I don't understand exactly how it works, or what the code in the line means.
What do
exports
andmodule.exports
actually mean?
I believe the 2nd piece of code allows the functions in the file to access methods
, but again, how exactly does it do this.
Basically, what are these magic words: module
and exports
?