Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

index.js vs main.js

It's pretty simple!

If your application is to be used in other applications: index.js

If your application is NOT to be used in other applications: server.js or app.js

As stated earlier the reasons being, when invoking npm start, if not defined in package.json, looks automatically for server.js. And when including another module into your application, it looks for index.js.

Extra: I also tend to only use index.js as a file name when this is automatically found somehow. This makes me aware if the file is invoked directly or indirectly.

When using npm init it makes the default index.js.
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged:
ADD COMMENT
Topic
Name
8+1 =