Created
February 24, 2016 00:41
-
-
Save etoxin/b448f813c98bd0d157b1 to your computer and use it in GitHub Desktop.
json, ajax, xhr, http on node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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