Here is my code:
var express = require('express'),
app = express.createServer(express.logger());
app.use(express.bodyParser());
app.get('/', function(request, response) {
var name = request.param('name', null);
response.header('Content-Type', 'text/event-stream');
var t = setInterval(function(){
response.write('Hello World by '+name+' (using http-1.1 streaming data!)<br />');
}, 2000);
/*request.socket.on('close', function() {
clearInterval(t);
}); */
});
var port = process.env.PORT || 5000;
app.listen(port, function() {
//clearInterval(t);
console.log("Listening on " + port);
});
I am using express because I am testing this in heroku and I used the guide there. So when I open the app I get a download popup with the data in the file (downloaded) instead of the html (dom) response.
What did I do wrong? (is it a browser problem?)
Edit:
@Joe, has solved my initial problem but yet, I have two questions:
1) Why i don't need to insert a 'correct' content type? (of streaming?)
2) Why does this code out put only after along time (about half a minute).?