I need to make a get request to an API that will give me a string that I will then use in my app, however I can't seem to do this easily.
I've done the following but it doesn't work.
function updateClients() {
var jsonData = "";
request('http://api.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
var jsonData = body;
}
});
console.log(jsonData);
io.sockets.emit('update', jsonData);
}