Node.js未处理的'错误'事件 [英] Node.js unhandled 'error' event
本文介绍了Node.js未处理的'错误'事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我编写了一个简单的代码并将其保存在文件try.js中。
I have written a simple code and save it in file try.js .
var http = require('http');
var makeRequest = function(message) {
var options = {
host: 'localhost', port: 8080, path: '/', method: 'POST'
}
var request = http.request(options, function(response){
response.on('data', function(data){
console.log(data);
});
});
request.write(message);
request.end();
}
makeRequest("Here's looking at you, kid.");
当我通过终端运行它时会出错
When I run it through terminal it give an error
throw er; // Unhandled 'error' event,
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)error' event
推荐答案
对我来说,问题是另一个实例正在运行。搜索正在运行的其他节点实例并将其终止。它应该在之后正确恢复。
For me, the problem was another instance was running. Search for other node instance running and kill it. It should resume properly after.
这篇关于Node.js未处理的'错误'事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文