Skip to content

Instantly share code, notes, and snippets.

@krist00fer
Created October 29, 2014 00:11
Show Gist options
  • Save krist00fer/be38ce50d4eac3526fe1 to your computer and use it in GitHub Desktop.
Save krist00fer/be38ce50d4eac3526fe1 to your computer and use it in GitHub Desktop.
Make HTTP GET Request and retrieve data as a JSON Object
var http = require('http');
function httpGetJSON(url, callback) {
http.get(url, function(res) {
var body = '';
res.on('data', function(data) {
console.log('httpGetJSON - data received', data);
body += data;
});
res.on('end', function() {
console.log('httpGetJSON - all data received', body);
callback(null, JSON.parse(body));
});
}).on('error', function (err) {
// An error occurred while calling url
callback(err, null);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment