About require function #49345
-
Node packaged the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
require() resolves paths relative to the module that calls it. A single global require() doesn't know what module calls it, not in enough detail to function properly. It's technically possible to reconstruct the caller's details through V8's C++ API but that's slower and more complicated than an IIFE. |
Beta Was this translation helpful? Give feedback.
-
Thank you for your help. I think, there is still a lot details of modular implementation of Nodejs to learn for me. |
Beta Was this translation helpful? Give feedback.
require() resolves paths relative to the module that calls it. A single global require() doesn't know what module calls it, not in enough detail to function properly.
It's technically possible to reconstruct the caller's details through V8's C++ API but that's slower and more complicated than an IIFE.