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

标签 node.js

我是 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/

相关文章:

node.js - 使用node上传图片到Heroku并获取其url

javascript - 如何一个接一个地依次运行 Gulp 任务

node.js - Node 中不能需要 CoffeeScript

node.js - 使用 Node 设置 Windows PATH 变量?

javascript - 使用 multer 上传多个文件?

node.js - 使用 Sails 服务 StyleSheet 和 JS

node.js - 在 Strongloop 环回中重写关系远程方法

node.js - 达到速率限制后的退避策略

node.js - 从 swift 容器下载时文件损坏

javascript - 在 Node 中使用 process.argv 时,对象类型是字符串的名称而不是字符串本身