gpt4 book ai didi

Node.js – 事件 js 72 抛出未处理的 'error' 事件

转载 作者:IT老高 更新时间:2023-10-28 21:51:30 30 4
gpt4 key购买 nike

我是 Node.js 的新手,希望使用流运行程序。对于其他程序,我必须同时启动一个服务器(mongodb、redis 等),但我不知道我是否应该用这个运行一个服务器。请让我知道我哪里出了问题以及如何纠正这个问题。提前致谢。

这是程序:

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 应用程序重新启动终端并再次运行程序。


另一台服务器可能也在使用您用于 nodejs 的相同端口。 杀死正在使用 nodejs 端口的进程并运行应用程序。

查找正在使用port:8000的应用程序的PID

$ fuser 8000/tcp
8000/tcp: 16708

这里的 PID 是 16708 现在使用 kill [PID] 命令杀死进程

$ kill 16708

关于Node.js – 事件 js 72 抛出未处理的 'error' 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22960703/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com