2
The console.log(Return) is ok, but only Undefined’s return, could anyone tell me why?
let result = [];
module.exports = {
async atualizar() {
await request(url, (err, res, body) => {
if (err) return console.log(err);
var $ = cheerio.load(body);
$('.coin-table tr').each(function() {
var name = $(this).find('th a').text().trim();
var valor = $(this).find('.text-right').text().split('R$');
if (name) {
result.unshift({ Nome: name, Valor: 'R$ ' + valor[1] });
}
});
console.log(result);
return result;
});
}
};
the file requesting the function:
const router = require('express').Router();
const buscar = require('./busca');
router.get('/atualizar', async (req, res) => {
console.log(await buscar.atualizar());
res.status(200).send('ok');
})
Add forehead
return
beforeawait request
– Sergio
I tried, but returns empty, I believe that it does not even execute the request if I play the Return before
– Guilherme Oliveira
What function/library is this
request
?– Sergio
Node.js Request module import
– Guilherme Oliveira
You are using the library
request
(npm)? Please include this detail in your question.– Luiz Felipe