Skip to content

Instantly share code, notes, and snippets.

@etoxin
Created February 24, 2016 00:41
Show Gist options
  • Select an option

  • Save etoxin/b448f813c98bd0d157b1 to your computer and use it in GitHub Desktop.

Select an option

Save etoxin/b448f813c98bd0d157b1 to your computer and use it in GitHub Desktop.
json, ajax, xhr, http on node.js
var http = require("http");
http.get(weatherApi, function(res) {
var body = '';
// get chunks of data and add it to body
res.on('data', function(chunk){
body += chunk;
});
// on end
res.on('end', function(){
// parse the body
var weatherResponse = JSON.parse(body);
console.log(weatherResponse);
});
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment