Node.js错误:连接ECONNREFUSED [英] Node.js Error: connect ECONNREFUSED

查看:1211
本文介绍了Node.js错误:连接ECONNREFUSED的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

I am on the OS X 10.8.2 trying this from CodeRunner and the Terminal. I have also tried putting my module in the node_modules folder.

我可以说这是一些有点连接问题,但我不明白为什么?

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:

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;


推荐答案

可能你与node.js的垂死挣扎每当您呼叫的服务器拒绝连接时。试试这个:

Chances are you are struggling with the node.js dying whenever the server you are calling refuses to connect. 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.

这篇关于Node.js错误:连接ECONNREFUSED的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆