最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

Node.js错误:连接ECONNREFUSED

IT培训 admin 6浏览 0评论

Node.js错误:连接ECONNREFUSED

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

我在OS X 10.8.2上尝试使用CodeRunner和终端。我也尝试将我的模块放在node_modules文件夹中。

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

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:

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

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

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;
回答如下:

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

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

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

Node.js错误:连接ECONNREFUSED

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

我在OS X 10.8.2上尝试使用CodeRunner和终端。我也尝试将我的模块放在node_modules文件夹中。

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

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:

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

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

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;
回答如下:

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

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

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

与本文相关的文章

发布评论

评论列表 (0)

  1. 暂无评论