var http = require('http');
var s = http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello\n');
setInterval(function() {
res.end(' World\n');
},2000);
console.log("Hello");
});
s.listen(8080);
在启动上述服务器后,我运行:curl http://127.0.0.1:8080
我获得了所需的延迟。输出:
Hello <2 seconds> World
但是在浏览器中,整个内容加载需要2秒钟。
Hell World <together after 2s>
我做错了什么?