-1

Function

function getpage(link, callback){
  var options = {
     method: 'GET',
     uri: link,
     headers: {
       'Authorization': 'Basic ' + new Buffer("c64f80ba83d7cfce8ae74f51e263ce93:").toString('base64')
     }
  };
  request(options, function (err, response, body) {
     callback(body);
  });
}

Code working when:

getpage('https://docs.google.com/feeds/get_video_info?formats=ios&mobile=true&docid=0BxG6kVC7OXgrQ1V6bDVsVmJMZFU', console.log);

But not working when

var text = getpage(link, console.log);
console.log(text);

How do I fix it? I want data to return the same. I want to use the data in other function.

Thanks

Saugat
  • 1,309
  • 14
  • 22

1 Answers1

0

You need a callback function.

getpage(link, function(data){
  var text = data;
  console.log(text);

  // Do something with your text here
});

Read more about callbacks and asynchronous call here.

Community
  • 1
  • 1
Saugat
  • 1,309
  • 14
  • 22