I was just trying to understand modules in node. I understood few things like node creates a module wrapper function around code placed in each file.
Let's say there are 2 files, a.js and b.js
In a.js, when i require b.js for first time, how will the module wrapper function which is present in b.js get's executed.
Does node do something like, get the whole content of b.js file as a string and then execute that from a.js using eval
and then keep the result of this function call in cache.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…