Created
April 14, 2010 17:35
-
-
Save alunny/366093 to your computer and use it in GitHub Desktop.
print out a crockford fact, just like that!
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
// 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