Skip to content

Instantly share code, notes, and snippets.

@alanhoff
Created July 4, 2014 17:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alanhoff/95975feda0b646657a50 to your computer and use it in GitHub Desktop.
Save alanhoff/95975feda0b646657a50 to your computer and use it in GitHub Desktop.
API de stream igual a do Twitter
var http = require('http');
// Criando o servidor para o proxy
http.Server(function(req, res){
res.writeHead(200, {
'Content-Type' : 'application/json; charset=utf-8',
'Transfer-Encoding' : 'chunked'
});
setInterval(function(){
res.write(JSON.stringify({
hello : 'Hello world', date : new Date()
}) + '\n');
}, 1000);
}).listen(8080);
setTimeout(function(){
var client = http.get('http://local.server:8080', function(res){
res.on('data', function(data){
console.log(data.toString());
});
});
}, 3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment