---
title: "How do I make HTTP requests in Node.js without axios?"
description: "Node has a built-in fetch, so most projects no longer need axios. Learn how to send GET and POST requests, handle errors and status codes, and add timeouts."
url: https://www.danny.engineering/answer/nodejs/how-do-i-make-http-requests-in-nodejs-without-axios
author: Danny
published: 2026-11-27T00:00:00.000Z
updated: 2026-11-27T17:23:00.000Z
tags: ["Node.js"]
---

# How do I make HTTP requests in Node.js without axios?

## The short answer


Use the global `fetch`. It is built into Node, stable since Node 21 and available in every supported release, with no package to install. It works the same way as `fetch` in the browser.


```javascript
const response = await fetch('https://api.example.com/users/1');

if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

const user = await response.json();
```


## Why it happens


For years Node only had the low-level `http` and `https` modules, which need a lot of code for a simple request. Libraries such as axios and node-fetch filled that gap. Node now ships its own `fetch`, powered by the undici HTTP client, along with `Request`, `Response`, `Headers`, `FormData` and `AbortController`.


The main difference from axios is how errors work. `fetch` only rejects when the request cannot be made at all, for example a DNS failure or a refused connection. A `404` or `500` response is still a successful promise, so you have to check `response.ok` yourself. It also does not parse JSON or set a timeout for you.


## How to fix it


### Send a GET request with query parameters


Build the URL with `URL` and `URLSearchParams` so values are encoded correctly.


```javascript
const url = new URL('https://api.example.com/search');
url.searchParams.set('q', 'node fetch');
url.searchParams.set('limit', '10');

const response = await fetch(url, {
  headers: { Accept: 'application/json' },
});
const results = await response.json();
```


### Send JSON in a POST request


Set the method, a `Content-Type` header, and a body made with `JSON.stringify`. axios does this conversion for you; `fetch` does not.


```javascript
const response = await fetch('https://api.example.com/users', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    Authorization: `Bearer ${process.env.API_TOKEN}`,
  },
  body: JSON.stringify({ name: 'Ada', role: 'admin' }),
});

if (!response.ok) {
  throw new Error(`Request failed: ${response.status} ${await response.text()}`);
}

const created = await response.json();
```


### Add a timeout


Pass `AbortSignal.timeout()` as the `signal`. If the request takes too long, it rejects with a `TimeoutError`.


```javascript
try {
  const response = await fetch('https://api.example.com/slow', {
    signal: AbortSignal.timeout(5000),
  });
  console.log(await response.json());
} catch (error) {
  if (error.name === 'TimeoutError') {
    console.error('Request took longer than 5 seconds');
  } else {
    throw error;
  }
}
```


### Wrap it in a small helper


If you liked axios because it threw on error status codes and parsed JSON, a few lines give you the same behaviour.


```javascript
export async function getJson(url, options = {}) {
  const response = await fetch(url, {
    ...options,
    signal: options.signal ?? AbortSignal.timeout(10_000),
    headers: { Accept: 'application/json', ...options.headers },
  });

  if (!response.ok) {
    const error = new Error(`HTTP ${response.status} for ${url}`);
    error.status = response.status;
    throw error;
  }

  return response.json();
}
```


### Upload files with FormData


```javascript
import { openAsBlob } from 'node:fs';

const form = new FormData();
form.append('file', await openAsBlob('report.pdf'), 'report.pdf');

await fetch('https://api.example.com/upload', { method: 'POST', body: form });
```


Do not set `Content-Type` yourself here. `fetch` adds the correct multipart boundary.


## Common pitfalls

- Assuming a `404` throws. Always check `response.ok` or `response.status`.
- Reading the body twice. `response.json()` and `response.text()` can only be called once; use `response.clone()` if you need both.
- Forgetting `JSON.stringify` on the body, which sends the text `[object Object]`.
- Not reading or cancelling the body of responses you ignore. Unread bodies can keep connections open; call `await response.body?.cancel()` if you do not need it.
- Expecting cookies to be kept between requests. Node's `fetch` has no cookie jar; pass the `Cookie` header yourself.

## Related reading

- [Node.js: Globals, fetch](https://nodejs.org/api/globals.html#fetch)
- [MDN: Using the Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch)
