title: Trying node.js author: Filippo Diotalevi date: 2011/05/04

Trying node.js

Published by Filippo Diotalevi on 4th May 2011 (last update 4th May 2011)

After a few months of Rails development, I start to really enjoy working with dynamic languages. Coming from a Java background, it takes some time to get used to work without a proper IDE with code completion and good refactoring tools; however, after a while the development experience becomes more natural, especially if you pair a dynamic language with a schema free database like MongoDB.

I was really curious to try some other (dynamic) way to develop web applications, so I decided to build a website to sell my old furniture, and I picked node.js because... well, a lot of people is talking about it. I understand that's not a sensible reason to choose a technology but hey, I just wanted to sell a few things. Have a look at the result, if you are interested (I still have a good wardrobe for sale, anyway).

At the end of the development, these are my notes/impressions.

Overall development experience
Developing the website has taken me about 12 hours. I estimate I spent roughly 30% of the time to google for information, and 20% to integrate the design. So development is reasonably quick.
Programming a web application in a event-driven fashion (the node.js way) feels a bit weird, but it's not a problem for simple webapps. I can imagine that if you need to write some complicate business logic that might be quite challenging though.

Node.js and Express
Node.js is a low-level framework, so if you want to develop a web application you better use Express. Express is a minimal web framework, similar to Sinatra. It's well documented in the website, and very quick to get started.

Jade
Since the Express documentation states that Jade is Haml successor, I figured that was the right choice. Wrong. For two reasons.
First, jade is basically undocumented. The Github page gives you some hints, but really not enough to write even a simple web application. Pro tip: the source code contains a examples/ folder.
Second reason: jade is very similar to Haml. Except that it is different. It feels similar, but some small details are different, so that (if you happen to work also with Haml like I'm doing) you keep making annoying errors.

MongoDB integration
I used node-mongodb-native and mongoskin to integrate the web application with MongoDB. Documentation here is still very minimal, and you have to figure out things via trial and error. But anyway, every MongoDB driver works basically in the same way.

Deployment on Duostack
One of the reason I chose the Node.js+MongoDB stack is to be able to deploy the application, for free, on Duostack. Duostack is the Heroku for Node.js, with some nice additions like the availability of MySQL, MongoDB and Redis to store your data. And a very reasonable free plan that allows to install your application with a 128MB database.
Duostack works exactly like Heroku; you push your code in production via git, and everything works. The application feels actually a bit slower than some of my applications deployed on Heroku, but I haven't really done any benchmark. It's free! so I can't complain.


In summary
Node.js and Express are enjoyable technologies to use, but really in their infancy. They're also in constant development, and incompatibilities are likely to be introduced in new versions. Their documentation is quite good, but the whole set of frameworks/technologies that you need to use to implement a full web application (templating, authentication, authorisation) is not. So expect to spend a lot of time to google for solutions, and to ask/answer questions in mailing lists and stackoverflow.
Also, I'm not convinced the event-driven approach can cope well with websites with complex business logic; it would help to have some books or at least a best practice collection to refer in this case, but I couldn't find anything.
On the other side, if you need to implement a network server, node.js is certainly worth having a good look.