require(X)

1. X is a core module, such as PATH/HTTP

Go straight back to the core module and stop looking

2. X is based on/or… / or /(root directory)

3. Direct is an X (no path), and X is not a core module.

In D: baidu cloud disk study \node\node example \test1\b.js compiled

require(‘abc’)

A node has a module object. Each module is a Module object. If you view this module object (console.log(module)) in the current module, you can get the path of the current module (as shown above).

So node_modules, look for node_modules in the current folder, if you don’t find node_modules, go up to the next folder and look for node_modules until you find node_modules

If none of the preceding paths is found, an error is reported: not found