Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Node.js Basics 2017 Handling Errors in Node Organizing Your Code with require

Michael Williams
PLUS
Michael Williams
Courses Plus Student 8,059 Points

This video went waaaaaaaay over my head. Can someone explain it to me like I'm 5? Or 3, even?

I get that you're drawing in the info from one file to another, but I don't get Andrew's explanation. Here's the video: https://teamtreehouse.com/library/organizing-your-code-with-require

4 Answers

Kevin Gates
Kevin Gates
15,053 Points

I think he is trying to separate the logic / ideas. So the profile.js is the main JavaScript code where you actually have a lot of processing going on.

Separate from that concern is his app.js file which is where he wants to manage his inputs / outputs.

By separating concerns, he has modularized his code. This means if he creates another file, let's say an API for another application he has, he could make that API code to also utilize that same profile.js file.

Additionally, if he knows his profile.js file works, that means if an error occurs, he has smaller groupings of code to debug.

To summarize:

  1. It's cleaner to see (organization).
  2. Separating concerns and modularizing allows you to easily reuse portions of your code.
  3. Its organization can improve debugging.

Hope this was helpful. :)

Rick Gleitz
Rick Gleitz
47,876 Points

Adding to what Kevin Gates said, it's pretty much the same reason we have separate CSS and JavaScript files for a website rather than putting it all in-line in the HTML file.