Dinesh D'Souza Dinesh D'Souza - 1 month ago 4x
Node.js Question

Loading a Folder Module in NodeJS

I have a folder called main.

Inside the 'main' folder I have 3 JS files.

index.js, app.js and dummy.js

Loading the main folder in the entry.js

var main = require('./main');

once I ran the entry.js,
the pointer is always going to index.js even if Iam not mentioned that path anywhere.

How will I point to some other JS inside the main folder?


First of all this is the basic functionality in the Folder module load as the flow will always go to the index.js if you are not configuring the js path in the package.json file.

If you want to point the flow to other JS file inside the main folder, you have to use package.json with the required js path.

sample is given below:-

create a package.json inside your main folder with the following properties.


"name" : "main",
"main" : "./dummy.js" (JS path)

Hope this clarifies your doubt.