Hi I'm trying to get the id variable that it's returned inside request in an asynchronous process using request and cheerio.
I've tried by returning a Promise but that didn't work.
let id;
request(mainUrl, function(err, res, body) {
let $ = cheerio.load(body)
var links= $(".book").map(function(){
return $(this).attr("href");
}).get()
var url= links[0]
var getId= url.match(/book\/show\/(\d+)/)
id= getId[1]
//This is the id I'm getting: "36474"
return Promise.resolve(id)
});
.then((value)=>{
console.log(id)
})