Below is my code...
async function getItemDetalil(url) {
const $ = await request(url, (err, res, body) => {
return cheerio.load(body);
});
console.log($);
}
Why my '$' is undefined? I assume it will be a cheerio object?
Below is my code...
async function getItemDetalil(url) {
const $ = await request(url, (err, res, body) => {
return cheerio.load(body);
});
console.log($);
}
Why my '$' is undefined? I assume it will be a cheerio object?
Why async/await variable return undefined?
await x
evaluates to the value of x
or, if that value is a promise, to the value the promise resolves to.
Example:
// Value
(async function() {
console.log('Normal value', await 42);
}());
// Promise resolution
(async function() {
console.log('From promise:', await Promise.resolve(42));
}());
If $
is undefined
, then request()
either returns undefined
or a promise that resolves to undefined
(unlikely). Have a look at its documentation or source code to find out what exactly is happening.
I assume it will be a cheerio object?
It would only be cherrio object iff request
actually returns a cherrio object or a promise that resolves to a cherrio object.
How do I convert an existing callback API to promises? might help you to solve your actual coding problem.