Registry / http-networking / axios
library1.20.0jsnpm✓ verified 24d ago

Axios is a popular promise-based HTTP client for both the browser and Node.js, enabling developers to make HTTP requests with a familiar API. The current stable version is 1.15.0, and the library maintains an active development cycle with frequent patch and minor releases, often including critical security updates and compatibility improvements.

npm install axios
INSTALL
IMPORT
SIG · AXIOS
A
axios
http-networkingjavascriptv1.20.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v1.20.0 · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
node 18
2/3 runs
2/3 runs
node 20
2/3 runs
2/3 runs
node 22
2/3 runs
2/3 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

axios
import axios from 'axios';
import { axios } from 'axios'; // Incorrect for default export const axios = require('axios'); // CommonJS import pattern
Axios exports its main functionality as a default export. For CommonJS environments, `require('axios')` is the correct approach.
AxiosRequestConfig, AxiosResponse, AxiosError
import type { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios';
import { AxiosRequestConfig, AxiosResponse, AxiosError } from 'axios'; // Imports types as values, can cause issues or larger bundles
When importing only types, use `import type` to ensure they are stripped during compilation, preventing accidental runtime imports and optimizing bundle size, especially in TypeScript projects.
axios.create
import axios from 'axios'; const instance = axios.create({ baseURL: 'https://api.example.com' });
import { create } from 'axios'; // `create` is a method of the default `axios` export, not a named export.
Custom Axios instances, which allow for distinct configurations (e.g., different `baseURL`, headers), are created by calling the `create` method on the default `axios` export.

This quickstart demonstrates a basic GET request to a public API, including asynchronous execution and robust error handling to differentiate between Axios-specific errors and general JavaScript errors.

import axios from 'axios'; async function fetchData() { try { const response = await axios.get('https://jsonplaceholder.typicode.com/todos/1'); console.log(response.data); } catch (error) { if (axios.isAxiosError(error)) { console.error('Axios error:', error.message); console.error('Status:', error.response?.status); } else { console.error('Unexpected error:', error); } } } fetchData();
Debug
Known issues
breakingAxios versions prior to v1.0.0 (and v0.31.0 for the v0.x branch) were vulnerable to Header Injection and Proxy Bypass. This was due to insufficient sanitization of outgoing header values and improper `NO_PROXY`/`no_proxy` enforcement.
fix
Upgrade to Axios v1.0.0+ or v0.31.0+ immediately to apply security hardening, which sanitizes header values and correctly enforces `NO_PROXY`.
affects: <1.0.0, <0.31.0
breakingA Denial of Service (DoS) vulnerability (prototype pollution) could occur when processing specifically crafted configuration objects utilizing the `__proto__` key in `mergeConfig`.
fix
Upgrade to Axios v1.13.5+ or v0.30.3+ to patch this vulnerability and prevent potential DoS attacks.
affects: <1.13.5, <0.30.3
deprecatedAxios previously used Node.js's deprecated `url.parse()` internally, which could lead to console warnings in recent Node.js environments.
fix
Upgrade to Axios v1.15.0+ to resolve Node.js deprecation warnings related to `url.parse()` usage.
affects: <1.15.0
breakingVersion 1.14.0 introduced `proxy-from-env` v2 alignment and `main` entry compatibility fixes. Users relying on environment-based proxy behavior or specific CommonJS resolution edge cases should validate their integration.
fix
Thoroughly test your application's proxy configurations and CommonJS module resolution after upgrading to v1.14.0 or later to ensure continued compatibility.
affects: >=1.14.0
gotchaA bug existed in versions 1.13.3 and 1.13.4 where the `AxiosError` object could intermittently be missing the `status` field, impacting error handling logic that relies on this property.
fix
Upgrade to Axios v1.13.5+ to ensure the `status` field is reliably present on `AxiosError` objects.
affects: 1.13.3 - 1.13.4
gotchaPrior to v1.13.2, applications using `keep-alive` requests with timeouts in Node.js could experience 'socket hang up' errors.
fix
Upgrade to Axios v1.13.2+ to fix the 'socket hang up' bug for keep-alive requests when using timeouts.
affects: <1.13.2
gotchaA regression in versions prior to v1.13.1 caused the data stream to be interrupted for responses with non-OK HTTP statuses, preventing full response body retrieval.
fix
Upgrade to Axios v1.13.1+ to resolve the regression and ensure complete data stream reception for responses with any HTTP status.
affects: <1.13.1
Errors
Common errors & fixes
TypeError: axios is not a function
This typically occurs when `axios` is incorrectly imported as a named export (`import { axios } from 'axios';`) or when a CommonJS `require()` statement is used in an ES module context without proper setup.
fix
For ES Modules, use `import axios from 'axios';`. For CommonJS, use `const axios = require('axios');`.
TypeError: Cannot read properties of undefined (reading 'status')
Attempting to access `error.response.status` when `error.response` is undefined. This happens if the error is not an HTTP response error (e.g., network error, request timeout, or a JavaScript error), meaning no `response` object was generated.
fix
Always check `if (axios.isAxiosError(error) && error.response)` before trying to access `error.response` properties. For network errors without a response, `error.code` (e.g., 'ECONNABORTED', 'ERR_NETWORK') can be useful.
Network Error (browser) / Error: connect ECONNREFUSED (Node.js)
The request failed to reach the server. This could be due to the server being offline, an incorrect URL, lack of internet connectivity, firewall issues, or a browser-specific CORS policy blocking the request.
fix
Verify the target URL is correct and accessible. Check the server's status, your internet connection, and any local firewall settings. In a browser, inspect the console for CORS-related error messages.
AxiosError: Request failed with status code 401
The server received the request but rejected it due to authentication issues, typically meaning missing, invalid, or expired credentials.
fix
Ensure your request includes the correct and current authentication credentials (e.g., API key, JWT bearer token) in the headers or body as required by the API you are calling.
Upgrade
Version history
1.20.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
46 hits · last 30 days
node
40
OpenAI (training)
1
Resources