I'm trying to write a wrapper that lets me call an API using http.get. However, callback never seems to complete; it returns but then seems to block the event loop.
I have a dummy function below that removes the logic that builds my API url and just accepts a pre-built URL. If I run this in the repl, I'll never get back to the prompt, the body of the page will be printed and then just sit there.
function Request(url, callback){
var data = '';
http.get(url, function(res){
res.on('data', function(chunk){
data += chunk.toString();
});
res.on('end', function(){
var obj = data;
callback(obj);
});
}).on('error', function(e) {
console.log("Got error " + e.message);
});
}
Any advice or pointers in the right direction would be appreciated. I'm running v0.8.15.