#####In the context of Node, what is a module?
- modules are self-contained chunks of code that serve a specific purpose
- equivalent to a Ruby class
- module.exports is anything that is exposed from one file to another. It can be a constructor, function, variable, etc.
#####The code examples from the second blog post look very different from the first. Why?
- the second article uses RequireJS, which loads asynchronously and packages the module in a define/require function.
- in the example, they return variables/methods within the define function. This define method seems to wrap everything, but only the pieces that are exported are returned.
- can pass other module dependencies into the define function ex: define(["models/Person", "my/utils"]), function (Person, utils) {...}
- require is used when the dependencies are loaded immediately
- Should we default to require or define?
- module.exports to expose anything we want
- module.exports.User; => var u = new user.User();
- module.exports = User; => var u = new user();
- function
- var power = function(level) { return x}
- module.exports = powerLevel => require('./powerLevel')(9050)