I've written a node.js page to grab some data from the flick API and then insert it into a database.
The code works perfectly on linux-- but when I moved it to a Windows machine running the latest version of node.js it seems that the data isn't parsing correctly.
var options = {
host: 'api.flickr.com',
port: 80,
path: '/services/rest/?method=flickr.photos.search&api_key=aa96a1b927fbf005374eb19d811ed529&tags=cars&format=json&nojsoncallback=1&page='+page
};
http.get(options, function(res){
var data = '';
res.on('data', function (chunk){
data += chunk;
});
res.on('end',function(){
var obj = JSON.parse(data);
console.dir(obj.photos.photo); // empty array on Windows, fine on linux!
})
});
I also verified the data by making a test request in a web browser for the same data-- the photos.photo element should definitely be populated.
Is there a reason this could be happening, such as I'm missing a library or plugin on Windows? Or could memory be affecting this?
As pointed out by JohnnyHK in the comments, the random page being appended to the API url was requesting pages that were out of range for the API. Rather than return an error (like a 404 or something for no page existing) the API returns an empty photos array.