We have always used file extension to provide details about the file. And in the scenario where we dont provide an extension we provide the details of the file with sheBang #!/usr/bin/env node
which informs that it is executable file with node.
I forgot to add the shebang information and ran the file without extension and it worked perfectly fine.
// test file (no .js extension)
const app = require("app");
console.log(app)
similarly, i removed the app.js extension to test again
const express = require("express");
const app = express();
module.exports = app;
if(require.main === module) console.log("No Errors");
if you run the node test
it works perfectly fine.
The question is Why?
If it works fine then why do we need to define extension explicitly for javascript?