From here.
What does “require” do?
The basic functionality of require is:
it reads a JavaScript file,
executes the file,
and then proceeds to return the exports object. An example module:
1 | console.log("evaluating example.js"); |
So if you run var example = require(‘./example.js’), then example.js will get evaluated and then example be an object equal to:
1 | { |
How does “require” find the target file?
1 | if (path.startsWith('./')) { |
For more detailed information, see the official docs.