Slide 16
Slide 16 text
var http = require('http');
var server = http.createServer(function (req, res) {
res.writeHead(200, { 'content-type': 'text/html' });
res.write('console.log("start of the stream...")');
var timer = setInterval(function () {
if (res.connection.writable) {
// keep sending a script with logging
res.write('console.log("and more...")');
} else {
// else connection has closed, and we can't write anymore
// so clear this interval, and *attempt* to end the response
clearInterval(timer);
res.end();
}
}, 2000);
});
server.listen(8080);
http://tick.rem.io