Created
March 18, 2015 09:26
-
-
Save gabhi/5287805abc7cb1dfe3a1 to your computer and use it in GitHub Desktop.
node js streaming response example
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
var express = require('express') | |
var app = express() | |
app.get('/', function(req, res) { | |
res.write('<html><head>'); | |
res.write('<body>'); | |
res.write("hello"); | |
res.write("<ol>"); | |
var i = 0; | |
setInterval(function() { | |
res.write("<li>" + i+++"</li>"); | |
}, 4000); | |
//res.end('</body></html>'); | |
//res.send('Hello World!'); | |
}) | |
var server = app.listen(3000, function() { | |
var host = server.address().address | |
var port = server.address().port | |
console.log('Example app listening at http://%s:%s', host, port) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment