Node.js isn't a silver bullet, but it's still a bullet.

If you're using Node.js, you're doing life wrong

This morning, on a conference mailing list, I made some disparaging remarks about Node.js (the title of this post, in fact). A couple people asked me why I felt that way. Rather than respond individually, I'll just list my reasons here —

I really don't understand all the hate for Node.js. It seems like many of the articles and rants against Node.js assume that Node.js was supposed to be good at everything. It's not. Just like every other framework and language in existence, it's good at some things and bad at others.

Node.js, at least from my understanding, was designed to be great at transporting small bits of information around the internet very quickly, and in real-time. Server-side events, instant messaging apps, real-time games, and collaboration tools are all great example of this. Take for example Trello. Trello is a real-time collaboration app that leverages and Node.js to enable real-time propagation of events and state-changes between clients. You could do the same thing with long-polling ajax or even frequent polling, but those both come with the cost of tying up unnecessary worker threads on the server and dealing with extra requests. Node.js on the other hand is inherently great at this. It's asynchronous event based architecture makes receiving, processing, and sending real-time events simple, painless, and very fast.

At the same time, Node.js isn't isn't especially good at computation. If for example you were trying to build an API to return the nth number in the Fibonacci sequence, Node.js would almost certainly be a bad choice? Why? The whole reason to use Node.js is based around the idea of not waiting on things. Instead of waiting for a db query to return results, it just triggers a db query and sets a callback event. Then, while the query is processing, your program can be doing other things (like handling another request). This is what makes Node.js seem so fast, without actually using more than 1 CPU core. In our example of computing Fibonacci numbers, however, the program doesn't need to wait on anything. The speed at which such an API can return results is directly linked to how fast it can compute a result. So here it would be better to use another, computationally faster language like Haskell or Scala.

So what's the point of all this? The point is that it's silly and irrational to complain that a framework isn't good at completing task A, when it was only ever designed to do task B. Node.js is extraordinarily good at what it was designed to do- so don't rant that it's bad at something else.

You can discuss this post on Hacker News.