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

I don't understand why we exported only the get function

Hello, as I was watching this video the teacher made a module with most of the code inside it. I don't understand why we exported only on part of the module. Why? the code needs the whole module to work.. Somewhere I am confused. It would be great if someone could explain it to me.

Thanks, Stavros

1 Answer

Hi Stavros,

get is the only function exported because it's the only function you'd actually call in the main app. Meaning, all other functions in profile.js are used by the get function so they aren't called by the main app directly. When get is called, it has access to the other functions in profile.js so it works correctly.

Hope that helps!

Great answer you made me understand it, I thought that something like that was happening under the hood but I wanted to somewhat sure. Anyways great answer thank you very much!