Skip to content

Instantly share code, notes, and snippets.

@BenziAhamed
Created March 10, 2013 19:37
Show Gist options
  • Save BenziAhamed/5130063 to your computer and use it in GitHub Desktop.
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"
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();
@BenziAhamed
Copy link
Author

Usage example

In a terminal type > node getfact.js
There are 293 ways to make change for a U.S. dollar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment