Skip to content

Instantly share code, notes, and snippets.

@alunny
Created April 14, 2010 17:35
Show Gist options
  • Save alunny/366093 to your computer and use it in GitHub Desktop.
Save alunny/366093 to your computer and use it in GitHub Desktop.
print out a crockford fact, just like that!
// using node 1.90
var sys = require('sys'), http = require('http');
var crockfordator = http.createClient(80, 'crockfordfacts.com');
var req = crockfordator.request('GET', '/',
{
'accept':'application/json',
'host':'crockfordfacts.com'
}
);
req.addListener('response', function (response) {
var fact = "";
response.addListener('data', function (chunk) {
fact= fact + chunk;
});
response.addListener('end', function () {
fact = JSON.parse(fact);
sys.puts(fact.fact + " -- " + fact.credit);
});
});
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment