Home > Web Front-end > JS Tutorial > Output of the HTTP response delivery process in nodejs

Output of the HTTP response delivery process in nodejs

巴扎黑
Release: 2017-05-14 14:31:58
Original
1166 people have browsed it

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);//能生成进程,并传输进程输出的流服务,并根据需要结束子进程
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template