Skip to content
Advertisement

Node.js project naming conventions for files & folders

What are the naming conventions for files and folders in a large Node.js project?

Should I capitalize, camelCase, or under-score?

Ie. is this considered valid?

JavaScript

Advertisement

Answer

After some years with node, I can say that there are no conventions for the directory/file structure. However most (professional) express applications use a setup like:

JavaScript

An example which uses this setup is nodejs-starter.

I personally changed this setup to:

JavaScript

In my opinion, the latter matches better with the Unix-style directory structure (whereas the former mixes this up a bit).

I also like this pattern to separate files:

lib/index.js

JavaScript

lib/static/index.js

JavaScript

This allows decoupling neatly all source code without having to bother dependencies. A really good solution for fighting nasty Javascript. A real-world example is nearby which uses this setup.

Update (filenames):

Regarding filenames most common are short, lowercase filenames. If your file can only be described with two words most JavaScript projects use an underscore as the delimiter.

Update (variables):

Regarding variables, the same “rules” apply as for filenames. Prototypes or classes, however, should use camelCase.

Update (styleguides):

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement