I'm trying to modify a variable when I'm inside a request. But I don't know why it doesn't get modified.
const request = require("request");
var all = JSON.parse(body);
var steamplayer = all['response']['players']['player'][0];
var sgameh = "Nessun gioco";
request({
url: "https://example.com",
method : 'GET'
}, function (error, response, body){
var sgameall = JSON.parse(body);
var fgame = sgameall['response']['games'].filter(function(item) {
return item.appid == steamplayer.gameid;
});
sgameh = parseFloat(fgame[0].playtime_forever / 60).toFixed(2);
console.log(sgameh) // THIS WORKS, BUT IT ISN'T WHAT I WANT
})
console.log(sgameh) // SHOULD RETURN A NUMBER, BUT RETURN Nessun gioco