ECONNREFUSED on running localhost server from NodeJS
NickName:Guest9875 Ask DateTime:2019-08-28T19:54:41

ECONNREFUSED on running localhost server from NodeJS

I have a NodeJS server up and running on my local machine that is listening to port 50000. From another server, that is also running on my local machine, I need to make a simple GET request to that server, but all I get is an ECONNREFUSED error:

{ Error: connect ECONNREFUSED 127.0.0.1:50000
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1106:14)
  errno: 'ECONNREFUSED',
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 50000 }

My request looks as follows, using request:

var options = {
    url: "http://localhost:50000",
    method: "GET"
}
request(options, function(error, response, body) {
    if (error) {
        console.log("[" + getDateTime() + "] Error connecting to localhost:");
        console.log(error);
        return;
   }
   // continue ...

I know that the server is up and running and that the endpoint is defined, because I can do the request to that exact same url in postman or in my browser and get a response, but somehow not in my NodeJS code.

Anybody have an idea?

Copyright Notice:Content Author:「Guest9875」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57691836/econnrefused-on-running-localhost-server-from-nodejs

Answers
Mohammed Amir Ansari 2019-08-28T12:15:38

The possible issue is that some else process is already running on the same port you are trying to use, either change your port or kill the existing process on your port. To kill the process on port you can try:\n\nFor mac:\n\nsudo kill $(lsof -t -i:8000) \n# or \nsudo fuser -k -n tcp 8000 \n# or \nfuser -k 8000/tcp\n\n\nAnd for windows check this\n\nhope this helps :)",


sid 2019-08-28T12:22:06

You might be running both the servers on the same port, kill another server on same port. \n\nIf you're on linux, you can kill port using sudo fuser -k -n tcp 5000 \n\nor if you're using windows: taskkill /PID 5000 /F",


More about “ECONNREFUSED on running localhost server from NodeJS” related questions

ECONNREFUSED on running localhost server from NodeJS

I have a NodeJS server up and running on my local machine that is listening to port 50000. From another server, that is also running on my local machine, I need to make a simple GET request to that

Show Detail

nodeJS request POST To localhost:3000 ECONNREFUSED

At one point I just want to make a POST request to my rails server running on localhost:3000 If a use like postman on even cUrl I can ping my API But kow, with my node app I want to do this : ...

Show Detail

nodejs: How to wait for server start at http://localhost:8000

I am starting the server from my script and then want to execute my tests. But when I start the server the server start process doesn't return as it is running and control is not returned back. The

Show Detail

ECONNREFUSED mysql nodejs

I'm trying to follow the 'tutorial' on http://www.gianlucaguarini.com/blog/push-notification-server-streaming-on-a-mysql-database/ to get accustomed to node and node+mysql. It throws an error whilst

Show Detail

How can I call localhost from localhost (laravel, nodejs)?

I am writing an application with node and laravel. I am running small laravel local server which resolves to http://localhost:8000. i am also running a node server on localhost:3000. Then trying to...

Show Detail

NodeJS `net` module slow ECONNREFUSED on Windows

There seems to be a huge performance difference between Linux and Windows when handling errors on the net module of NodeJS. I was handling an ECONNREFUSED error on Windows which seemed to be almost...

Show Detail

Sending a request from a deployed Nodejs server to a localhost nodejs server

I have a nodejs application that is currently running on my localhost that prints labels from the printer connected to my computer. I am using this node-printer library. I am planning to deploy t...

Show Detail

Jhipster fails with: "[HPM] Error occurred while trying to proxy request /management/info from localhost:9000 to http://localhost:8080 (ECONNREFUSED)"

I am trying to create a simple project skeleton using jhipster. # Ubuntu 18.04 node -v # v10.15.1 npm -v # 6.4.1 jhipster --version # 6.0.0 jhipster # (I only press enter, so that the defaults are

Show Detail

NodeJS Mongodb in docker compose = ECONNREFUSED

I try to up a Node.JS container linked with a MongoDB container by docker-compose, but systematically node.js return an ECONNREFUSED error. The error nodejs_1 | /code/node_modules/mongoose/

Show Detail

ECONNREFUSED for Postgres on nodeJS with dockers

I'm building an app running on NodeJS using postgresql. I'm using SequelizeJS as ORM. To avoid using real postgres daemon and having nodejs on my own device, i'm using containers with docker-compos...

Show Detail