问题描述
我是Node.js的新手,希望使用流来运行程序.使用其他程序,我必须同时启动服务器(mongodb,redis等),但是我不知道是否应该以此来运行服务器.请让我知道我要去哪里哪里以及如何纠正此问题.预先感谢.
I'm new to Node.js and wish to run a program using streams. With other programs, I had to start a server simultaneously (mongodb, redis, etc) but I have no idea if I'm supposed to run one with this. Please let me know where I am going wrong and how I can rectify this. Thanks in advance.
这是程序:
var http = require('http'),
feed = 'http://isaacs.iriscouch.com/registry/_changes?feed=continuous';
function decide(cb) {
setTimeout(function () {
if (Date.now()%2) { return console.log('rejected'); }
cb();
}, 2000);
}
http.get(feed, function (res) {
decide(res.pipe.bind(res, process.stdout));
//using anonymous function instead of bind:
// decide(function () {
// res.pipe(process.stdout)
// });
});
这是cmd输出:
<b>C:\05-Employing Streams\05-Employing Streams\23-Playing with pipes>node npm_stre
am_piper.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: Parse Error
at Socket.socketOnData (http.js:1583:20)
at TCP.onread (net.js:527:27)
</b>
推荐答案
关闭在另一个shell中运行的nodejs app
.重新启动终端,然后再次运行该程序.
Close nodejs app
running in another shell.Restart the terminal and run the program again.
另一台服务器可能还使用了与nodejs相同的端口. 杀死使用nodejs port
并运行该应用的过程.
Another server might be also using the same port that you have used for nodejs. Kill the process that is using nodejs port
and run the app.
查找使用 port:8000
$ fuser 8000/tcp
8000/tcp: 16708
PID为 16708 ,现在使用kill [PID]
命令终止该进程
Here PID is 16708 Now kill the process using the kill [PID]
command
$ kill 16708
这篇关于Node.js –事件js 72抛出未处理的“错误"事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!