Skip to content

Instantly share code, notes, and snippets.

@lancehudson
Created October 16, 2015 01:47
Show Gist options
  • Save lancehudson/a5e7b642cb9ce0a58f38 to your computer and use it in GitHub Desktop.
Save lancehudson/a5e7b642cb9ce0a58f38 to your computer and use it in GitHub Desktop.
Top Reddit
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