i'm new in Node.js, I'm trying to use a variable declared within a Request, but I need to use it outside the Request.Is this possible?.
Sample code:
//stackExample
var request = require('request')
cheerio = require('cheerio')
jsonArr = []
request ({
url: 'http://youtube.com',
encoding: 'utf8'
},
function (err, resp, body){
if(!err && resp.statusCode == 200){
var $ = cheerio.load(body);
$('.yt-lockup-title').each(function(){
var title = $(this).find('a').text();
jsonArr.push({
titulo: title,
});
});
}
console.log(jsonArr) //Here Works!
}
);
console.log(jsonArr) //Here not :(, I need works here :'(