FG
๐Ÿ”Œ APIs & SDKs

Axios returns ECONNREFUSED 127.0.0.1:80 but port is set to 8080

Freshabout 22 hours ago
Mar 14, 20260 views
Confidence Score68%
68%

Problem

Describe the bug Axios returns ECONNREFUSED 127.0.0.1:80 but port is set to 8080 To Reproduce While having an express server returning 200 on http://localhost:8080/ (and confirmed via browser), running the following returns the error provided (see additional context) [code block] Expected behavior Axios sends an http request to the port specified in the url Environment Im indirectly using axios@0.21.1 (start-server-and-test -> wait-on -> axios@0.21.1). - Axios Version [0.21.1 - Adapter HTTP - Node.js Version v12.8.0 and v15.8.0 - OS: macOS 10.15.6 Additional context/Screenshots Error: [code block]

Error Output

error provided (see additional context)

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix โ€“ Awaiting Verification

Fix Axios ECONNREFUSED by Correcting Port Configuration

Medium Risk

The error ECONNREFUSED indicates that Axios is attempting to connect to the wrong port (80) instead of the specified port (8080). This is likely due to the URL being incorrectly formatted or the Axios request not specifying the correct port in the request URL.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Verify Express Server Configuration

    Ensure that your Express server is correctly set to listen on port 8080. Check your server code for the listen method.

    javascript
    app.listen(8080, () => { console.log('Server running on http://localhost:8080'); });
  2. 2

    Check Axios Request URL

    Make sure that the Axios request is targeting the correct URL with the specified port. The URL should be 'http://localhost:8080/' and not 'http://localhost/' or 'http://127.0.0.1/'.

    javascript
    axios.get('http://localhost:8080/').then(response => console.log(response.data)).catch(error => console.error(error));
  3. 3

    Update Axios Version

    Consider updating Axios to a more recent version if possible, as there may be bug fixes or improvements that could resolve underlying issues.

    bash
    npm install axios@latest
  4. 4

    Test the Connection

    After making the changes, run your application and test the Axios request again to ensure it connects successfully to the Express server on port 8080.

    bash
    node yourApp.js

Validation

To confirm the fix worked, check the console logs for the successful response from the Axios request. You should see the expected data returned without any ECONNREFUSED errors.

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

axioshttpapi