Skip to content

Instantly share code, notes, and snippets.

@brennanholtzclaw
Forked from rrgayhart/require-1511.markdown
Last active May 24, 2016 21:30
Show Gist options
  • Save brennanholtzclaw/1011609cd78f8a639128481ea20c0cdd to your computer and use it in GitHub Desktop.
Save brennanholtzclaw/1011609cd78f8a639128481ea20c0cdd to your computer and use it in GitHub Desktop.
The Concept of Require

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 and answer the following questions:

  • In the context of Node, what is a module?

A module in Node feels a lot like a class or other namespace in Ruby. However, simply requiring the file doesn't do the full job. You do have to export the module, to allow it to be sent out and used in other places. This can help prevent the pollution of the global namespace, I guess. (A very "green" way to code) You keep extraneous and private functions/variables hidden away, and only expose what you want to.

  • The code examples from the second blog post look very different from the first. Why?

This code is using RequireJS to load in modules. I need more code examples, I think, to fully understand how this is better/faster/cleaner than how you would normally require in Node. It seems like it's related to dependencies, but I don't fully get it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment