Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
162 views
in Technique[技术] by (71.8m points)

javascript - Node.js错误:连接ECONNREFUSED(Node.js Error: connect ECONNREFUSED)

I am new to node and running into this error on a simple tutorial.

(我是节点新手并在一个简单的教程中遇到此错误。)

I am on the OS X 10.8.2 trying this from CodeRunner and the Terminal.

(我在OS X 10.8.2上尝试使用CodeRunner和终端。)

I have also tried putting my module in the node_modules folder.

(我也尝试将我的模块放在node_modules文件夹中。)

I can tell this is some kind of connection problem but I have no idea why?

(我可以说这是某种连接问题,但我不明白为什么?)

events.js:71
        throw arguments[1]; // Unhandled 'error' event
                       ^
Error: connect ECONNREFUSED
    at errnoException (net.js:770:11)
    at Object.afterConnect [as oncomplete] (net.js:761:19)

app.js:

(app.js:)

var makeRequest = require('./make_request');

makeRequest("Here's looking at you, kid");
makeRequest("Hello, this is dog");

make_request.js:

(make_request.js:)

var http = require('http');

var makeRequest = function(message) {

    //var message = "Here's looking at you, kid.";
    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();
};

module.exports = makeRequest;
  ask by ian translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Chances are you are struggling with the node.js dying whenever the server you are calling refuses to connect.

(当你正在调用的服务器拒绝连接时,你很可能正在努力使用node.js。)

Try this:

(试试这个:)

process.on('uncaughtException', function (err) {
    console.log(err);
}); 

This keeps your server running and also give you a place to attach the debugger and look for a deeper problem.

(这可以使您的服务器保持运行,还可以为您提供附加调试器的位置,并寻找更深层次的问题。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...