Bootstrap your node.js project in the cloud

So you have a great website idea and you want to build and bring that first version online as fast as you can. You figured that node.js is the way to go. You kick-off the development and after a couple of hours of hacking you realize that although you’re progressing at breakneck speed you’re missing a few important bits:

  • – How do I better structure my project?
  • – I want to test this thing. I want unit tests, UI (headless browser) tests and public API tests (I want that API offering out too of course)
  • – I want proper CSS and html templating
  • – Looks like I need non-trivial request routing, I need more than the default provided

Oh, and after you have all of this, you want to be able to deploy it to a node-ready cloud environment like Heroku without hassle.

Enter bootstrap.js.

It bootstraps the application structure, integrates technologies for templating, routing, etc. and as importantly, comes with the option of pushing the application to the cloud.

Project structure
The project structure, influenced by this suggestion is:

controllers/
views/                <-- view templates
public/               <-- public files
public/stylesheets    <-- stylus css files
spec/                 <-- BDD tests and web service tests
test/                 <-- unit tests

The bootstrapping also creates a git repo for your convenience.

Technologies
Bootstrap.js comes integrated with:

  • Express framework for routing
  • Jade template engine
  • Stylus CSS generator
  • – JQuery 1.5.2

A word about testing
Nodejs applications are particularly interesting from a testing perspective given the asynchronous nature of the language itself but I found that the tests are especially valuable when trying-out different technologies since testing is the best way to validate them. Bootstrap.js’s tests are structured to provide the more important aspects of application testing: there are basic unit, BDD and public API tests that are shipped along, giving the developer a starting point to add more tests in those areas as the development progresses. Look in the test/ and spec/ directories for them.

Cloud deployment
Although the bootstrapping can be done locally, the more exciting option is to drop your web application in a hosted environment (and show it off your friends afterwards). There are currently two cloud environments supported: Heroku and Joyent’s no.de. Both have native node support and integrate with your code via git and both making a live service upgrade as easy as “git push”.

Do contribute
I welcome your suggestions/improvements. Get and fork the code for others to enjoy!