Search code examples
javascriptnode.jsexpresscode-structureexpress-generator

Why use bin/www and not index.js?


The express-generator tool creates a file called bin/www and uses it as the application's main entry-point. I believe I've seen a couple of other modules do this as well, but the vast majority simply use index.js.

What is the rationale behind this? Of course I understand why you would split the server and the code for setting up the program into a separate modules, but why bin/www and not index.js? Why nest the main-entry point to a program two levels deeper than the stuff it calls? And remove the file-extension, making it even less descriptive?

Is there a clever, non-obvious reason behind this? Should I use this for my node-modules as well?

Thank you!

[edit]:

All good answers, thank you folks! I've accepted the one pointing out that this is standard behaviour for packages that include executables. Here's some more reading I've come across on this:


Solution

  • You're used to running npm run, but not sysadmin. He will look for executables (attribute x) in thebin directory.

    The entry point index.js is for node module. All packages that provide commands to run on the console contain the bin directory.

    The extension is removed because it is not a script, but as a program. And these do not have extensions.