You develop Node.js code in separate files, called modules. There are three module types:
- Core modules, which you can load anywhere
- Dependency modules, which you can also load anywhere
- Local modules, which you need to load based on the relative path
Modules are loaded synchronously and cached. So, a repeated load will actually not be a load; instead, Node.js will pass you a reference to the already loaded module. This is true for all three types of modules:
# loading a JSON file with settings from same path as moduleconst settings = require("./settings");
Local modules are simple files where you need to know the relative or full path. You can also load a path and Node.js will look up the index.js file inside it. You can also load ...