After a few years with node, I can say that there are no conventions for the directory / file structure. However, most (professional) express applications use customization, for example:
/ /bin - scripts, helpers, binaries /lib - your application /config - your configuration /public - your public files /test - your tests
In an example that uses this setting, nodejs-starter .
I personally changed this setting to:
/ /etc - contains configuration /app - front-end javascript files /config - loads config /models - loads models /bin - helper scripts /lib - back-end express files /config - loads config to app.settings /models - loads mongoose models /routes - sets up app.get('..')... /srv - contains public files /usr - contains templates /test - contains test files
In my opinion, this is more in line with the unix-style directory structure (while above it shifts a bit).
I also like this file sharing template:
Library /index.js
var http = require('http'); var express = require('express'); var app = express(); app.server = http.createServer(app); require('./config')(app); require('./models')(app); require('./routes')(app); app.server.listen(app.settings.port); module.exports = app;
<strong> lib / static / index.js
var express = require('express'); module.exports = function(app) { app.use(express.static(app.settings.static.path)); };
This allows you to completely disable the entire source code without worrying about dependencies. A real good solution to deal with unpleasant javascript. An example of a nearby real world that uses this setting.
Update (file names):
With regard to file names, the most common are short names in lower case. If your file can be described in just two words, most JavaScript projects use an underscore as a separator.
Update (variables):
As for variables, the same "rules" apply to file names. Prototypes or classes, however, must use a camel case.
Update (style):