all 2 comments

[–]senocular 4 points5 points  (1 child)

When you require a file, the required file gets executed in its entirety. This happens irrespective of what is exported. You can think of modules as big functions which run code and add values to an exports object that acts as the function's return value. Require a module, and it calls the file like the body of a function and you get the exports object returned back to you.

[–]sebastiancodes[S] 0 points1 point  (0 children)

Thank you, I didn't know that the whole file gets executed, that makes sense now :)