Reputation: 1496
To simplify, let's have an entry.js
, which requires common.js
(with very universal functions), and routines.js
(which contains project-specific functions). routines.js
too requires common.js
.
I don't expect the above scenario to be a problem, but in general, are the multiple requires, by modules which require one another a bad practice and is there a better approach? I'm thinking requiring within the entry.js
and passing over to functions. Or is this microoptimizing and multiple requires are no big deal?
Upvotes: 0
Views: 25
Reputation: 353
I don't imagine this being a big deal as Node caches each "require" for you as long as the resolved filename is exactly the same (in most instances it will be, however the node docs list some cases where it may not be)
I found this post to have a nice simple explanation of how the module/require system in node works.
Upvotes: 1