I am running a server using Node.js and need to request data from another server that I am running (localhost:3001
). I need to make many requests (~200) to the
Try this:
var async = require("async");
var request = require("request");
var show_file = function (file_number,cb) {
//..Sync ops
var file_index = Math.round(Math.random() * 495) + 1;
var pinnacle_file_index = 'http://localhost:3001/generate?file='+file_index.toString();
//request instance from Request npm Module
//..Async op --> this should make async.each asynchronous
request(pinnacle_file_index, function (error, response, body) {
if(error)
return cb(error);
var object_key = "file_" + file_number.toString();
pinnacle_data[object_key] = JSON.parse(body);
return cb();
});
};
async.each(
lookup_list,
show_file,
function (err) {
if(err){
console.log("Error",err);
}else{
console.log("Its ok");
console.log(pinnacle_data);
}
});