{ res.writeHead(200, { 'content-type': 'text/html' }); res.write('<script>console.log("start of the stream...")</script>'); var timer = setInterval(function () { if (res.connection.writable) { // keep sending a script with logging res.write('<script>console.log("and more...")</script>'); } 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