Created
March 10, 2013 19:37
-
-
Save BenziAhamed/5130063 to your computer and use it in GitHub Desktop.
MentalFloss.com has a great amazing facts section online. Here is a NodeJS version of it for command line happiness.
To use, run as "node getfact.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'); | |
var options = { | |
host: 'mentalfloss.com', | |
path: '/api/1.0/views/amazing_facts.json?limit=1&display_id=xhr&bypass=1' | |
} | |
var request = http.request(options, function (res) { | |
var data = []; | |
res.on('data', function (chunk) { | |
data = JSON.parse(chunk.toString()); | |
}); | |
res.on('end', function () { | |
console.log(unescape(data[0].fact_body.replace(/<(?:.|\n)*?>/gm, ''))); | |
console.log(' '); | |
}); | |
}); | |
request.on('error', function (e) { | |
console.log(e.message); | |
}); | |
request.end(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage example
In a terminal type > node getfact.js
There are 293 ways to make change for a U.S. dollar.