I'm learning how to do a crawler (using 'cheerio') for a personal project. The crawling itself is working fine, but somehow the object I'm constructing (eventDetails) is not being returned. You can see below that the object, declared at the function level, is properly populated withing the request, but not outside it. Can you please help? Thanks.
function crawlEventDetails(eventLink){
var eventDetails = new Object();
//console.log(eventLink);
request(urlDomain + eventLink, function(err, response, html) {
if(err){
console.log(err);
}
else {
var $ = cheerio.load(html);
eventDetails.date = $('.detail.textsmall').eq(0).text();
eventDetails.time = $('.detail.textsmall').eq(1).text();
eventDetails.place = $('.detail.textsmall').eq(2).text();
eventDetails.price = $('.detail.textsmall').eq(3).text();
console.log(eventDetails); //OK!
}
});
console.log(eventDetails); //empty!
return eventDetails; // empty!
}