JSFiddle - React, Tailwind, and code Playground
JavaScript
exports.user = function (req, res) {
var user = req.body.steamid;
var http = require('http');
var parseString = require('xml2js').parseString;
var output = '';
var options = {
host: 'steamcommunity.com',
path: '/id/' + user + '/games?xml=1'
};
var pouet = function (callback) {
request = http.get(options, function (res) {
res.setEncoding('utf8');
console.log('STATUS: ' + res.statusCode);
res.on("data", function (chunk) {
output += chunk.toString('utf8');
callback(output);
});
}).on('error', function (e) {
console.log('ERROR: ' + e.message);
});
};
pouet(function (dataFromAjax) {
parseString(dataFromAjax, function (err, result) {
var totalSize = 0;
var steamID = result.gamesList.steamID;
var steamID64 = result.gamesList.steamID64;
var json = result.gamesList.games;
var query = Game.find(null);
//Run in each game and lets find if we found them in the bdd
for (var i = json[0].game.length - 1; i >= 0; i--) {
var totalSize = 0; // I could put that way earlier in code but it changes nothing
query.where('steamID', json[0].game[i].appID[0]);
query.exec(function (err, resultat) {
if (err) {}
for (var i = 0, l = resultat.length; i < l; i++) {
var game = resultat[i];
totalSize += game.size; //totalSize is set up to the right size
}
});
//totalSize fall to 0 and forget his past number
}
res.render('user', {
steamid: steamID,
steamid64: steamID64,
size: totalSize,
...