Created
December 30, 2015 20:16
-
-
Save tastywheat/7742fcd6cdf1d04d8372 to your computer and use it in GitHub Desktop.
server http persistent connection stream
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(); | |
var server = app.listen(3005); | |
var id = 1; | |
app.get('/stream', function (req, res, next) { | |
var clearId = setInterval(function() { | |
console.log('writing count ' + id); | |
res.write('count: ' + id++); | |
}, 1000); | |
req.on('close', function () { | |
console.log('closing'); | |
clearInterval(clearId); | |
res.end(); | |
}) | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment