Skip to content

Instantly share code, notes, and snippets.

@suissa
Created March 11, 2015 00:24
Show Gist options
  • Save suissa/8ba4062ee752a07fb895 to your computer and use it in GitHub Desktop.
Save suissa/8ba4062ee752a07fb895 to your computer and use it in GitHub Desktop.
API Stream with Node.js
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://localhost: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