Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tastywheat/7742fcd6cdf1d04d8372 to your computer and use it in GitHub Desktop.
Save tastywheat/7742fcd6cdf1d04d8372 to your computer and use it in GitHub Desktop.
server http persistent connection stream
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