Can Node.js use a different filename for the directory index file than `index.js`?
It's impossible.
The default filename is hardcoded and should be index.js
or index.node
according to this:
https://nodejs.org/api/modules.html#modules_folders_as_modules
source to share
It is hardcoded inside the node core, you can see it in action here: https://github.com/nodejs/node/blob/master/lib/internal/modules/cjs/loader.js#L224
As the documentation says, first it tries to get the package from node_modules, if there is no such package, it tries to get it from index.js from this folder, and as a last resort it tries to open the specified (if any) .json package in that folder. If nothing was found, it gives an error with a message about the absence of such a module
source to share