Node.jsAxiosError Fix2026 Updated

Axios Network Error in Node.js— Fixed [Complete Guide 2026]

January 20266 min readNode.js · Axios · All OS

⚡ Debug First — Network Error Has Multiple Causes

Debug Axios error
axios.get('/api/data').catch(error => {
  if (error.response) {
    // Server responded with error status (4xx, 5xx)
    console.log('Status:', error.response.status)
    console.log('Data:', error.response.data)
  } else if (error.request) {
    // Request sent but no response received
    console.log('No response:', error.request)
    console.log('Code:', error.code)  // ECONNREFUSED, ETIMEDOUT etc.
  } else {
    console.log('Request setup error:', error.message)
  }
})

What Causes Axios Network Error?

Error
AxiosError: Network Error
    at XMLHttpRequest.handleError (axios/lib/adapters/xhr.js:117:14)
# or in Node.js:
AxiosError: connect ECONNREFUSED 127.0.0.1:5000

Axios throws 'Network Error' when no response was received — the request never completed. This is different from a 4xx or 5xx error (where the server responded with an error). Network Error means something prevented the response from arriving at all.

ScenarioRoot CauseFix
Browser: works in Postman not browserCORS — browser blocking responseJump →
Node.js: ECONNREFUSEDServer not running on that portJump →
Request hangs then failsTimeout — server too slowJump →
SSL/TLS errorCertificate invalid or self-signedJump →
Wrong data in responseWrong base URL or endpointJump →
1

Diagnose With error.response and error.request

Identify the exact cause first
2 min
Complete Axios error handler
const handleAxiosError = (error) => {
  if (axios.isAxiosError(error)) {
    if (error.response) {
      // Server responded with non-2xx status
      console.error('Server error:', error.response.status, error.response.data)
    } else if (error.request) {
      // Request was made but no response
      console.error('Network error - no response received')
      console.error('Error code:', error.code)
      // ECONNREFUSED = server not running
      // ETIMEDOUT    = server too slow
      // ERR_NETWORK  = CORS or DNS failure (browser)
    } else {
      // Request setup error
      console.error('Request error:', error.message)
    }
  }
}

// Usage
try {
  const res = await axios.get('/api/data')
} catch (error) {
  handleAxiosError(error)
}
2

CORS Error in Browser Context

Works in Node.js but fails in browser
2 min

In a browser, Axios Network Error is almost always a CORS issue. The request reaches the server but the browser blocks the response because the server is missing Access-Control-Allow-Origin.

server.js — fix on the backend
const cors = require('cors')
app.use(cors({ origin: 'http://localhost:3000', credentials: true }))

Check the browser Network tab in DevTools. If the request shows a red CORS error, the fix is on the server — not in Axios.

3

Wrong Base URL or Endpoint

404 or no response
1 min
Verify your Axios config
// Log the full URL Axios is requesting
axios.interceptors.request.use(config => {
  console.log('Requesting:', config.baseURL + config.url)
  return config
})

// Common mistakes
axios.get('localhost:5000/api/data')        // ❌ missing http://
axios.get('http://localhost:5000api/data')  // ❌ missing /
axios.get('http://localhost:3000/api/data') // ❌ wrong port

// Correct
axios.get('http://localhost:5000/api/data') // ✅

// Best practice — set baseURL once
const api = axios.create({
  baseURL: process.env.REACT_APP_API_URL || 'http://localhost:5000',
  timeout: 10000,
})
4

Server Not Running (ECONNREFUSED)

Node.js: connect ECONNREFUSED
1 min

ECONNREFUSED means nothing is listening on that port. Start your backend server and verify the port.

terminal
# Verify server is running and on correct port
curl http://localhost:5000/api/health
# If this fails — server is not running

# Check what is on the port
lsof -i :5000         # macOS/Linux
netstat -ano | findstr :5000   # Windows

# Start your server
npm start
# or
node server.js
5

SSL Certificate Errors

DEPTH_ZERO_SELF_SIGNED_CERT / unable to verify
3 min
Node.js Axios — disable SSL in development
const https = require('https')

const api = axios.create({
  // Development only — NEVER in production
  httpsAgent: new https.Agent({ rejectUnauthorized: false })
})

// Production — use proper certificate
// or add your CA cert:
const httpsAgent = new https.Agent({
  ca: require('fs').readFileSync('/path/to/ca-cert.pem')
})
const api = axios.create({ httpsAgent })

Never use rejectUnauthorized: false in production. It disables certificate validation completely and makes HTTPS meaningless.

6

Timeout Configuration

Request hangs — ETIMEDOUT or ECONNABORTED
2 min
Axios timeout setup
// Set timeout on axios instance (milliseconds)
const api = axios.create({
  baseURL: 'http://localhost:5000',
  timeout: 10000,   // 10 seconds
})

// Or per request
axios.get('/api/slow-endpoint', { timeout: 30000 })

// Handle timeout specifically
axios.get('/api/data').catch(error => {
  if (error.code === 'ECONNABORTED') {
    console.error('Request timed out')
  }
})
7

Proxy Configuration

Corporate network or custom proxy
3 min
Axios proxy config
// Set HTTP proxy
const api = axios.create({
  proxy: {
    protocol: 'http',
    host: 'proxy.company.com',
    port: 8080,
    auth: { username: 'user', password: 'pass' }
  }
})

// Disable proxy for specific requests
axios.get('/api/data', { proxy: false })

// Use environment variables (Axios reads these automatically)
// HTTP_PROXY=http://proxy.company.com:8080
// NO_PROXY=localhost,127.0.0.1
8

Proper Axios Error Handling

Production-ready error handling pattern
3 min
api.js — production pattern
import axios from 'axios'

const api = axios.create({
  baseURL: process.env.NEXT_PUBLIC_API_URL || 'http://localhost:5000',
  timeout: 15000,
  withCredentials: true,
})

// Request interceptor — add auth token
api.interceptors.request.use(
  config => {
    const token = localStorage.getItem('token')
    if (token) config.headers.Authorization = `Bearer ${token}`
    return config
  },
  error => Promise.reject(error)
)

// Response interceptor — handle errors globally
api.interceptors.response.use(
  response => response,
  error => {
    if (error.response?.status === 401) {
      // Redirect to login
      window.location.href = '/login'
    }
    if (error.code === 'ERR_NETWORK') {
      console.error('Network error — check server and CORS')
    }
    return Promise.reject(error)
  }
)

export default api

How to Prevent Axios Network Errors

Frequently Asked Questions

What causes Axios Network Error?+
Axios throws 'Network Error' when no response was received at all — the request never reached the server or the server never responded. Causes: CORS error blocking the response in browser, wrong URL/port, server not running, SSL certificate issue, or network timeout.
Axios Network Error with no response — how to debug?+
Check error.request to see what was sent. In browser: check the Network tab in DevTools — the request may show a CORS error or failed DNS. In Node.js: add console.log(error.code) — ECONNREFUSED means the server is not running on that port.
Axios Network Error only in browser not in Node?+
The browser is blocking the response due to CORS. The request reaches the server but the browser discards the response because the server is missing Access-Control-Allow-Origin header. Fix CORS on your Express server.
How do I fix Axios ECONNREFUSED?+
The server you are trying to reach is not running. Start your backend server and verify the port number matches. Run: curl http://localhost:5000/api/test to verify the server responds.
How do I handle Axios errors properly?+
Check error.response for server errors (4xx, 5xx), error.request for network errors (no response received), and error.message for everything else. Use axios.isAxiosError(error) to check if it is an Axios error.
Axios SSL certificate error — how to fix?+
In development, you can disable SSL verification: httpsAgent: new https.Agent({ rejectUnauthorized: false }). In production, install the correct SSL certificate or add the CA cert. Never disable SSL verification in production.

Need Expert Help?

We Build Production-Grade Node.js Apps

Softplix builds full-stack applications. Dealing with API integration issues in production? We can help.

Talk to an Engineer