Skip to content

Instantly share code, notes, and snippets.

@Frijol
Last active August 29, 2015 14:01
Show Gist options
  • Save Frijol/9d5bf3d6dbd4cba169f0 to your computer and use it in GitHub Desktop.
Save Frijol/9d5bf3d6dbd4cba169f0 to your computer and use it in GitHub Desktop.
Making an HTTP GET with Node http module on Tessel
var http = require('http');
console.log('http get...');
http.get("http://api.openweathermap.org/data/2.5/weather?id=5327684&units=imperial", function(res) {
console.log(res.statusCode);
if (res.statusCode == 200) {
var body = '';
res.on('data', function(chunk) {
body += chunk;
console.log(body);
});
res.on('end', function() {
console.log('got end');
response = JSON.parse(body);
console.log('Temperature:', response.main.temp);
});
} else {
console.log(res.statusCode);
}
}).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