This article mainly introduces the output of the HTTP response transmission process in nodejs. It is very good and has reference value. Friends who need it can refer to it
No more nonsense, I will directly post the code for everyone. Yes, the specific code is as follows:
var spawn = require('child_process').spawn; require('http').createServer(function(req, res) { var child = spawn('tail', ['-f', '/var/log/system.log']);//当有一个新的请求出现时,就通过执行 tail -f /var/log/system.log命令启动一个新的进程 child.stdout.pipe(res);//将子进程的输出传入相响应主体中 res.on('end', function() { child.kill(); }); }).listen(4000);//能生成进程,并传输进程输出的流服务,并根据需要结束子进程
The above is the detailed content of Output of the HTTP response delivery process in nodejs. For more information, please follow other related articles on the PHP Chinese website!