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