Why can I call api port from React app using ip address, but not when I use “localhost”

Posted February 28, 2020 47.4k views

I can call curl -s localhost:3030 from command line and get a good reply. But when I call using axios or fetch within my React app, I get net::ERR_CONNECTION_REFUSED.

For example, this works:"", {

This does not work (net::ERR_CONNECTION_REFUSED):"http://localhost:3030/authentication", {
edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

Hi there @cyclops,

What I could suggest is checking what port your application has is binded to first. To do that SSH to your Droplet and then run:

  • netstat -plant | grep 3000

Also another thing you could check is if your localhost resolves correctly to the IP address:

  • ping localhost

Another thing that you need to keep in mind is that you need to run the axios script from the Droplet itself in order for it to work.

Feel free to share the output of the commands here so I could try to further advise you.

Hope that this helps!

localhost resolved to

netstat showed 3000 binding to 0 Not sure why, but it gives me an avenue to explore

Much appreciated!

  • Hi there @cyclops,

    No problem at all! Another thing that you could try is to SSH to your Droplet and run:

    telnet localhost 3000

    And see if you are getting a successful connection.


Hi @bobbyiliev ,

I’m facing same issue.

  • ping localhost successful
  • netstat -plant | grep 3000 shows tcp 0 0*
  • telnet localhost 3000 Trying Connected to localhost. Escape character is '^]'.

But still getting this error net::ERRCONNECTIONREFUSED

I’m using axios in react to make calls to node js. In my react app that’s my API_URL for login.

const API_URL = "http://localhost:3000";
  • Hello,

    Your application is binding on, and this is why you can not access it from the outside world.

    You need to change this to: and then you will be able to access it via