// ./main.js
require('./example-module').whoami();
// ./example-module.js
module.exports.whoami = () => console.log(`Hello, I'm a file`);
// Output: ./example-module.js
// ./example-module/index.js
module.exports.whoami = () => console.log(`Hello, I'm an index.js file inside a directory`);
// Output: ./example-module/index.js
Executing the main.js file described above will output Hello, I'm a file
as the file example-module.js
is given precendence over a directory of the same name, when the require
module attempts to resolve ./example-module
.