Created
October 16, 2015 01:47
-
-
Save lancehudson/a5e7b642cb9ce0a58f38 to your computer and use it in GitHub Desktop.
Top Reddit
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
var request = require('request'); | |
var getTopItems = function(url, cb) { | |
request.get(url, function(err, response, body) { | |
if (err) { return cb(err); } | |
if (response.statusCode !== 200) { return cb(body); } | |
cb(null, JSON.parse(body).data.children.map(function(item) { | |
return item.data; | |
})); | |
}); | |
}; | |
var url = 'http://www.reddit.com/r/gaming/top.json?limit=5'; | |
getTopItems(url, function(err, items) { | |
if (err) { return console.error(err); } | |
console.log(items.map(function(item) { | |
return item.title; | |
}).join('\n')); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment