Length | Points | Week |
---|---|---|
20 minutes | 10 | Week 2 |
When you start working with WebPack for GameTime, you'll notice that you can't just define a variable in one file and find it in another as easily as you can in Rails.
-
Read Node.js, Require and Exports and Organize Your Code with RequireJS
-
Fork This Gist
-
Respond in your forked gist with answers to the following questions
-
In the context of Node, what is a
module
?- In the context of Node, a module is considered a file that contains JS code. All code in that file is considered private until it is exported via
module.exports
. Once code is exported, it can be imported in a second file viarequire()
. Therefore, modules, or files, allow developers to organize their code in a logical way. Once organized, developers can use that code anywhere in the project as long as that code is exported from the source file and imported, or required, in the file that you would like the use the code.
- In the context of Node, a module is considered a file that contains JS code. All code in that file is considered private until it is exported via
-
The code examples from the second blog post look very different from the first. Why?
- This is because the second blog post uses RequireJS in order to create modules with the
define()
function. After reading the post, I still prefer themodule.exports
andrequire()
way of dealing with modules because it seems like a more pure appoach. I understand the value of RequireJS, and why some people may feel that it is appropriate, or helpful, to use in certain situations. However, I like the purest approach - don't use somthing unless you need it makes your project significantly better. Having said that, I see how RequireJS can make dealing with large projects easier. For example, rather than simply exporting and requiring files, RequireJS allows developers to create dependencies, or relationships. Creating these depencies, or relationships, it can make the code easier to understand and deal with. Simply, it answers the question of "what other code does this file depend or rely on?". I think it comes down to understanding when using RequireJS would be considered helpful and/or appropriate.
- This is because the second blog post uses RequireJS in order to create modules with the