Process nodejs search package

After performing npm install, if the package is successful, it will generate a node_modules folder in the current directory, which kept us required dependencies.

When you need a reference, for example:

var math = require("math");

nodejs first looks in the current directory exists node_modules folder, it exists will continue to look for math package in node_modules folder, if there is math package is referenced.

If you do not currently exist node_modules folder or folder does not exist node_modules math package, it will enter the parent directory of the current directory to find node_modules folder directory. . . To find in this manner, if still not find the root directory to find math package, will throw can not find dependent error.

 

Guess you like

Origin www.cnblogs.com/zjfjava/p/10993282.html