res.json(data) is called before redis client get data from server... How can i wait for data before send json object?
app.get('/api/player/:name', function(req, res) {
var name = req.params.name;
var data = {
"connected": 0,
"health": 0,
"armour": 0
};
readClient.get(name + '.connected', function(err, value) {
data.connected = value;
});
readClient.get(name + '.health', function(err, value) {
data.health = value;
});
readClient.get(name + '.armour', function(err, value) {
data.armour = value;
console.log(data);
});
console.log(data);
res.json(data);
});