Created
June 20, 2015 03:47
-
-
Save dd1994/4f4e0a1c1bb100c3f60a to your computer and use it in GitHub Desktop.
node http.get example
This file contains 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
'use strict'; | |
let http = require('http'); | |
let hnApi = 'http://node-hnapi.herokuapp.com/news'; | |
let news = ''; | |
let hackerNews; | |
let req = http.get(hnApi, function(res) { | |
res.on('data', function(chunk) { | |
news += chunk; | |
console.log('-----------------------------------------'); | |
}); | |
res.on('end', function() { | |
hackerNews = JSON.parse(news); | |
console.log(hackerNews[0]); | |
}); | |
}); | |
req.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment