Slow performance with JSON in Node.js

I'm new to node.js (and javascript in general) so I thought I would learn by creating a simple weather app utilizing YQL. Overall, the app is working but the request is extremely slow. It takes about ~6 seconds to return the json. On the other hand, I created the same app using jQuery(getJSON) and I get results almost immediately.

Is this the best way to parse json from an url in node.js?

var request = require('request');

var url = 'http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D96720&format=json&diagnostics=true&callback='

request(url, function (error, response, body) {
    console.log(body);
})

I'd appreciate any feedback and/or suggestions.

Thanks in advance.

I just tried to open that url in my browser and after > 10 seconds, it's still loading. (Update: it timed out.)

My guess is that, Yahoo is setting caching headers that your browser is respecting, so your first request was probably cached and then every jQuery request after that loaded from your browser cache nearly instantly. request() does not have a local cache, so it's downloading a fresh copy each time, which takes much longer.

Try clearing your browser cache and see if it runs as quickly - if the first request is slow then that would confirm my suspicion.

Update: here's some more info about request speeds:

  • My home internet connection: mostly timeouts. (Time Werner Cable / Road Runner; Western Ohio)
  • My prgmr.com server in california: fast - first request took 1.151 seconds in node.js, after that every request was < 0.1 seconds. Node v0.8.21
  • node.js web proxy running on heroku: fast - 0.28 seconds including the time to proxy it back to my laptop - http://www.nodeunblocker.com/proxy/http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20weather.forecast%20WHERE%20location%3D96720&format=json

So, I'm starting to think that maybe it's location dependent, and can say at the very least that node isn't slow. If nothing else, you can feel free to proxy requests through my heroku server. Note that it's a free account, so when heroku "idles" it, then the next request is slow or sometimes errors out.