This is a starting point for a NodeJS/Express project that aims at keeping the file structure relatively tidy.
Previous versions:
Client-side
- As with any Express project, all images, client-side JS and CSS are to go in their respective folders under
/public. - A
normalize.cssfile has already been added to the template to quickly start from a "clean" CSS point (thanks to necolas).
Server-side
app.jsis responsible for starting the application, declaring any application-wide requirements and passing these to the routerboot.js.boot.jsusesfsto list all the possible routes from the/routesfolder, then run these routes throughvm.- A file
config.sample.jshas been provided as a starting point and should be copied asconfig.js(and left ignored in.gitignorefor security reasons). It should contain any configuration parameters that may be platform specific and/or sensitive. - The
/viewsfolder works exactly as expected with Express,layout.jadefor your main layout, and then however many.jadefiles you need for your routes. A notifications area has been added by default to facilitate exposing your flash messages to the client. - Any files within
/routeswork as routes normally work in Express. There is no particular rule but the idea is to create a new file for each general piece of functionality (think controller in MVC).
If you'd like to expose any variables to your routes, don't forget to pass them to boot as a parameter (require('./boot')(app, config, fs/* other variables here */); in app.js and update boot.js accordingly)
If you're using a database you could create a /models folder at the root, and to avoid having to pass a whole list of models to boot, I suggest using something along the lines of var models = {}; in app.js and adding all your models to that hash, e.g. models.user = require('./models/host.js');. You can then use models.user.find() in your routes.
Simply clone this repo, navigate into it and run npm install -d. That's it!