Parsing Reddit API – JavaScript & NPM package ‘Request’

Since I recently got extremely interested in Node stuff I wanted to play around with consuming JSON APIs using some NPM packages. I found two that did the job:

Here’s my example using ‘request’. I parsed the API for the Kendama subreddit and rendered each post’s title and body.


var request = require(‘request’);

request(‘’, displayData);

function displayData(err, resp, body) {
if (err) {
var jsonString = JSON.parse(body);
var arrayOfPosts =;

for (var i = 0; i < arrayOfPosts.length; i++) { console.log('--' + arrayOfPosts[i].data.title); console.log(' ' + arrayOfPosts[i].data.selftext + '\n'); } } [/javascript] And the result [text] $ node consumeAPI.js --Thoughts on transparents? Thinking about getting a transparent ozora from roots and was curious if the thin paint would be more prone to chipping or getting messed up. --TK16? Are the yellow Tk16s from amazon good? Heres the link: --Sweets website down? I was looking to buy a HG but it looks like the websites down. Anyone know when ítll be back up? --Has anyone ordered from HiKendama? How is the paint, does it chip much? Sticky? Slick? How about the antique line? They look pretty rad, I kinda want one, but I am new to Kendama, so I am scared to spend the 30 dollars. --These look sick, anyone else gonna cop? [/text] Further Reading ---

Leave a Reply