Programing

Node.js 오류 : ECONNREFUSED 연결

lottogame 2020. 12. 2. 07:45
반응형

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);
}); 

이렇게하면 서버가 계속 실행되고 디버거를 연결하고 더 깊은 문제를 찾을 수있는 공간도 제공됩니다.


나는 유령과 헤 로쿠와 같은 문제를 겪고 있었다.

heroku config:set NODE_ENV=production 

해결했습니다!

서버가 실행중인 구성 및 환경을 확인하십시오.


localhost : 8080에 연결하려고합니다 ... localhost와이 포트에서 실행중인 서비스가 있습니까? 그렇지 않은 경우 연결이 거부되어이 오류가 발생합니다. 먼저 localhost : 8080에서 실행중인 항목이 있는지 확인하는 것이 좋습니다.


응답을 통해 요청을 반환하는 위의 코드를 실행할 때 포트 8080에서 서버를 실행해야합니다. 아래 코드를 별도의 파일 (예 : 'server.js')에 복사하고 node 명령 (node ​​server.js)을 사용하여이 서버를 시작하십시오. 그런 다음 별도의 명령 줄에서 위의 코드 (노드 app.js)를 별도로 실행할 수 있습니다.

var http = require('http');

http.createServer(function(request, response){

    //The following code will print out the incoming request text
    request.pipe(response);

}).listen(8080, '127.0.0.1');

console.log('Listening on port 8080...');

코드에 데이터베이스 연결이 있지만 아직 데이터베이스 서버를 시작하지 않은 경우 때때로 발생할 수 있습니다.

내 경우에는 mongodb와 연결할 코드가 있습니다.

mongoose.connect("mongodb://localhost:27017/demoDb");

after i started the mongodb server with the command mongod this error is gone


If you are on MEAN (Mongo-Express-AngularJS-Node) stack, run mongod first, and this error message will go away.


People run into this error when the Node.js process is still running and they are attempting to start the server again. Try this:

ps aux | grep node

This will print something along the lines of:

user    7668  4.3  1.0  42060 10708 pts/1    Sl+  20:36   0:00 node server
user    7749  0.0  0.0   4384   832 pts/8    S+   20:37   0:00 grep --color=auto node

In this case, the process will be the one with the pid 7668. To kill it and restart the server, run kill -9 7668.


Check with starting mysql in terminal. Use below command

mysql-ctl start

In my case its worked


The Unhandled 'error' event is referring not providing a function to the request to pass errors. Without this event the node process ends with the error instead of failing gracefully and providing actual feedback. You can set the event just before the request.write line to catch any issues:

request.on('error', function(err)
{
    console.log(err);
});

More examples below:

https://nodejs.org/api/http.html#http_http_request_options_callback


Same error occurs in localhost, i'm just changing the mysql port (8080 into localhost mysql port 5506). it works for me.


Run server.js from a different command line and client.js from a different command line

참고URL : https://stackoverflow.com/questions/14168433/node-js-error-connect-econnrefused

반응형