Skip to content

Instantly share code, notes, and snippets.

@ncb000gt
Forked from gaurish/gist:888555
Created March 27, 2011 03:59
Show Gist options
  • Save ncb000gt/888895 to your computer and use it in GitHub Desktop.
Save ncb000gt/888895 to your computer and use it in GitHub Desktop.
var http = require('http'),
util = require('util');
var options = {
host: 'api.twitter.com',
port: 80,
path: '/1/statuses/public_timeline.json'
};
var chunks = [],
total = 0;
http.get(options, function(res) {
console.log('Got response ' + res.statusCode);
}).on('data', function(chunk) {
chunks.push(chunk);
total+= chunk.length;
}).on('error', function(e) {
console.log('Got Error ' + e.message);
}).on('end', function() {
var buf = new Buffer(total)
cur = 0;
for (var i = 0, l = chunks.length; i < l; i++) {
chunks[i].copy(buf, cur, 0);
cur += chunks[i].length;
}
console.log(util.inspect(buf.toString(), true, 5));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment