Why node.js

I’ve moved from Python to Javascript on the server side – specifically, Tornado to Node.js.

Three years ago, I moved from Perl to Python because I got free hosting at AppEngine. Python’s a cleaner language, but that was not enough to make me move. Free hosting was.

Initially, my apps were on AppEngine, but that wouldn’t work for corporate apps, so I tried Django. IMHO, Django’s too bulky, has too much “magic”, and templates are restrictive. Then I tried Tornado: small; independent modules; easy to learn. I used it for almost 2 years.

The unexpected bonus with Tornado was it’s event-based model: it wouldn’t wait for file or HTTP requests to be complete before serving the next request. I ended up getting a fair bit of performance from a single server.

Trouble is, Python’s a rare skill. I tried selling Python in corporates a couple of times, and barring RBS (which used it before I came in, and made it really easy for me to build an IRR calculator), I’ve failed every time. Apart from general fear, uncertainty and doubt, getting people is tougher.

Javascript’s a good choice. It has many of Python’s benefits. It’s easy to recruit people. Corporates aren’t terrified of it. Rhino was good enough a server. All it lacked was the “cool” factor, which node.js has now brought it. And besides,

  • It’s fast. About 20 times faster than Rhino, by my crude benchmarks.
  • It’s stable. (Well, at least, it feels stable. Rock solid stable. Sort of like nginx.)
  • It’s asynchronous. So I don’t miss Tornado
  • It has a pretty good set of libraries, thanks to everyone jumping on to it
  • I can write code that works on the client and server – e.g. form validation

Bye, Python.

  1. Aravinda says:

    I started experimenting with nodejs and CouchDb couple of months ago. It is really awesome.

    A few good points to note about Node Js http://ncannasse.fr/blog/is_nodejs_wrong

  2. Safe Hammad says:

    Very interesting post. I’d be keen to learn which stack of libraries and frameworks you end up using on top of node.js and your experiences with them. Also, what are your experiences so far of using node.js in a production setting and how do they compare with, for example, deploying Python code in Tornado?

  3. Shankar V says:

    Oh Anand – Python I thought is such a wonderful language. That it is a rare skill should not be a reason to turn away from it. On the contrary, maybe it is good that the language is not getting dumbed down 😉

    Have you read this? – http://www.paulgraham.com/pypar.html

  4. Sathya says:

    Javascript, as Doug Crockford said, is a misunderstood language. I was under the impression that enterprises are quite wary about server side javascript. I am quite surprised to learn that companies are more open to Javascript than Python (given that Google embraces Python). Also, in India, developers look at javascript more as a UI-bells-and-whistles stuff and it is quite difficult to hire a Quality serverside js developer. Anyway … for rapid prototyping isn’t Python good enough ? You are anyway used to the quirks of Django etc for 3 yrs. Am sure node.js would be having some baggage elsewhere. Or is it the case that change is the only constant ?

  5. Philmod says:

    Which library do you use for both server and client form validation?

  6. S Anand says:

    I don’t have any at the moment, Phillippe — I’m writing my own at the moment. Do you know of any good ones?

  7. Luis says:

    If you like the benefits of JavaScript and node.js but you still miss python’s syntax and productivity, you may want to play with Coffeescript. Check it out, it’s addictive…

  8. S Anand says:

    Yes, I did play with it. It’s amazing. I’m waiting for a few more months, allowing it to get more popular, and once someone else on my team suggests it independently, we’ll jump into it!

  9. I am also learning node.js for school project. It’s really nice specially express.js, I love jade and stylus. 🙂
    For the DB, I use mongodb; It’s really cool.