In the course of learning about modules for Node.js, we've used the require and import features without going into detail about how modules are found and all the options available. The algorithm for finding Node.js modules is very flexible. It supports finding modules that are siblings of the currently executing module, or have been installed local to the current project, or have been installed globally.
For both require and import, the command takes a module identifier. The algorithm Node.js uses is in charge of resolving the module identifier into a file containing the module, so that Node.js can load the module.
The official documentation for this is in the Node.js documentation, at https://nodejs.org/api/modules.html.
The official documentation for ES6 modules also discusses how the algorithm differs, at https://nodejs.org/api/esm.html.
The official documentation for ES6 modules also discusses how the algorithm differs, at https://nodejs.org/api/esm.html.
Understanding the module resolution algorithm is one key to success with Node.js. This...