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

Michael Williams
Michael Williams
Pro Student 8,057 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:

3 Answers

Kevin Gates
Kevin Gates
14,640 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
17,428 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.