07 Apr 2010

nodejs just the right tool for ...

Recenly I moved my blog from kite_runner to jekyll . I wanted to know how many links that I referred in my previous posts were dead.

I wrote the code in nodejs and all it took was 84 lines . However the best part is that the running the code takes only 4 minues thanks to nodejs.

Here is what the code does.

  1. get a full list of articles in _posts directory .
  2. scan each of the articles looking for any links .
  3. make a GET request to each of those links and print the response return code .

Because of nodejs step2 is totally asynchronous and 200 files read simultaneously. Similarly when it comes to making a GET request to url there is no time being wasted in waiting to get the response because nodejs handles everything asynchronously.

I can’t image how much time it will take to get the result if it is written in ruby. Of couse you can do multi-threading but that’s a lot of work.

It seems nodejs is just the right tool if you are interacting with other services that might not be fast.