I know npm
looks for a package.json
in the current directory, but it also appears to find a package.json
several directories above my current directory. How does this work? Does npm
look at parent directories until it finds a package.json
?
If so, does require()
also search for a package.json
when looking for modules?
Is this behavior part of npm
or is it part of CommonJS?
npm
doesn't really do much work w/ package.json
except for all the heavy lifting of grabbing/resolving dependencies and putting them in the proper directory structure. To the bet of my knowledge, npm does not inject its self a runtime dependency.
Node's require()
performs the package.json
resolution/parsing at runtime, as well as interaction with the node_modules
directory.
Here's some pointers into the code that does that:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With