Node JS тело запроса к глобальному объекту - PullRequest
0 голосов
/ 17 апреля 2020

Это мой код. Функция getResult должна возвращать объект результата для всех require. getResult возвращает неопределенное значение после всех требований.

function getResult(){
    var result = {};

    getJsonCSGO(function(error, body){
        if (!error) {
            result.csgo = body; // is there a result
        }
    });

    getDota(function(error, body){
        if (!error) {
            result.dota = body; // is there a result
        }
    });

    return result; // undefined
}

async function getJsonCSGO(callback){
    await request('https://www.hltv.org/matches', function(error, response, body) {
        if (error) {
            console.log(error);
        } else {
            let $ = cheerio.load(body);
            res = $('.match-day').html();

            callback(null, res);
        }
    });
}
...