I have an question about how to call a variable inside annoymous function in node.js.
const client = require('cheerio-httpcli');
const url = 'https://puppetron.now.sh/render?url=https://festa.io/events';
client.fetch(url, (err, $, res) => {
if(err){
console.log(err);
return;
}
const firstItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(3) > div:nth-child(1)';
const secondItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(3) > div:nth-child(2)';
const thirdItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(3) > div:nth-child(3)';
const fourthItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(3) > div:nth-child(4)';
const fifthItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(4) > div:nth-child(1)';
const sixthItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(4) > div:nth-child(2)';
const seventhItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(4) > div:nth-child(3)';
const eighthItem = '#root > div > div:nth-child(1) > div.Responsive__DesktopView-yfth06-0.jdVFLa > div > div:nth-child(4) > div:nth-child(4)';
$(firstItem).each(function(post) {
firstItemName = $(this).text()
});
});
console.log(client.fetch.firstItem)
In this code, I want to console log the firstItemName outside of client.fetch.
First, I tried to console.log client.fetch.firstItem, but It didn't worked.
How can I call firstItemName variable outside of client.fetch?