Node.js – 事件 js 72 抛出未处理的“错误”事件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22960703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 17:08:18  来源:igfitidea点击:

Node.js – events js 72 throw er unhandled 'error' event

node.js

提问by user3514893

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.

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

This is the program:

这是程序:

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)
// });

});

This is the cmd output:

这是 cmd 输出:

<b>C:-Employing Streams-Employing Streams-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>

回答by Ganesh Pandey

Close nodejs apprunning in another shell. Restartthe terminal and runthe program again.

关闭nodejs app在另一个 shell 中运行。 重新启动终端并再次运行程序。



Another server might be also using the same port that you have used for nodejs. Killthe process that is using nodejs portand runthe app.

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

To find the PID of the application that is using port:8000

查找使用端口的应用程序的 PID :8000

$ fuser 8000/tcp
8000/tcp:            16708

Here PID is 16708Now kill the process using the kill [PID]command

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

$ kill 16708

回答by Vu Luu

I had the same problem. I closed terminal and restarted node. This worked for me.

我有同样的问题。我关闭了终端并重新启动了节点。这对我有用。

回答by lama12345

Well, your script throws an error and you just need to catch it (and/or prevent it from happening). I had the same error, for me it was an already used port (EADDRINUSE).

好吧,您的脚本会引发错误,您只需要捕获它(和/或防止它发生)。我有同样的错误,对我来说这是一个已经使用的端口(EADDRINUSE)。

回答by Bhojendra Rauniyar

I always do the following whenever I get such error:

每当我收到此类错误时,我总是执行以下操作:

// remove node_modules/
rm -rf node_modules/
// install node_modules/ again
npm install // or, yarn

and then start the project

然后启动项目

npm start //or, yarn start

It works fine after re-installing node_modules. But I don't know if it's good practice.

重新安装 node_modules 后它工作正常。但我不知道这是否是好的做法。

回答by Delino

Check your terminal it happen only when you have your application running on another terminal..

检查您的终端,只有当您的应用程序在另一个终端上运行时才会发生。

The port is already listening..

该端口已经在侦听..

回答by Gerbrand

For what is worth, I got this error doing a clean install of nodejs and npm packages of my current linux-distribution I've installed meteor using

值得一提的是,我在干净安装 nodejs 和我当前的 linux 发行版的 npm 包时遇到了这个错误,我已经使用

npm install metor

And got the above referenced error. After wasting some time, I found out I should have used meteor's way to update itself:

并得到了上面提到的错误。浪费了一些时间后,我发现我应该使用meteor的方式来更新自己:

meteor update

This command output, among others, the message that meteor was severely outdated (over 2 years) and that it was going to install itself using:

此命令输出,其中包括流星严重过时(超过 2 年)并且将使用以下命令自行安装的消息:

curl https://install.meteor.com/ | sh

Which was probably the command I should have run in the first place.

这可能是我应该在第一已运行命令的地方

So the solution might be to upgrade/update whatever nodejs package(js) you're using.

因此,解决方案可能是升级/更新您正在使用的任何 nodejs 包(js)。