Why doesn't fetch in Node.js work out of the box? What's the best alternative? or How do I use fetch

14 Replies, 706 Views

"Why doesn't fetch in nodejs work out of the box? What's the best alternative?"

Hey folks,

kinda weird that fetch in nodejs isn't just built-in, right? Like, it's everywhere in browsers but nope, not in Node by default.

So what's the move these days? I heard node-fetch was the go-to but it's deprecated now...

Is it just better to use axios? Or is there some other lightweight package?

Also, why didn't Node just include fetch in nodejs from the start? Feels like a missed opportunity lol.

Lemme know what y'all are using!

---

*(or if you prefer a shorter version...)*

"Simplest way to use fetch in nodejs?"

Trying to use fetch in nodejs but hitting a wall.

What's the easiest fix? Heard mixed things about node-fetch, undici, axios...

Just wanna make simple requests without overcomplicating it.

Tips? 😅
Yeah, fetch in nodejs isn't built-in because Node was designed before fetch became a standard in browsers. It’s kinda annoying, but there are solid alternatives.

Axios is great if you want something reliable with a clean API. But if you want something closer to the browser's fetch, try `undici`—it’s the modern replacement for `node-fetch` and is actually recommended by the Node team.

For lightweight stuff, `got` is another option. Honestly, just pick one and stick with it—they all work fine for simple requests.
Wait, node-fetch is deprecated? Damn, I missed that memo lol.

Anyway, undici is the new hotness for fetch in nodejs. It’s faster and more modern. Axios is still solid tho, especially if you need interceptors or better error handling.

If you’re lazy (like me), just do `npm install undici` and use `import { fetch } from 'undici'`. Done.
Fun fact: Node didn’t include fetch because it was originally server-side, and browsers handled client-side stuff. Now the lines are blurred, but legacy code makes it hard to just add fetch in nodejs overnight.

For alternatives, I’d say:
- Axios if you want stability.
- undici if you want speed and future-proofing.
- got if you like streams and fancy features.

Pick your poison!
ugh, same struggle here. fetch in nodejs should just work, but nope.

I switched to axios ages ago and never looked back. It’s got better defaults and less weird quirks than node-fetch ever did.

But if you’re allergic to dependencies, undici is the way. It’s like fetch, but not broken.
Honestly, the simplest fix rn is undici. It’s literally fetch for nodejs, just not global by default.

```js
import { fetch } from 'undici';
```

Axios is overkill unless you need it. node-fetch is dead. undici is the answer.
Why no fetch in nodejs? Because Node hates convenience, obviously.

Jk, but yeah, it’s historical. For alternatives:
- undici if you want fetch but better.
- axios if you want more features.
- got if you’re a masochist who loves streams.

I’d go undici. It’s the closest to what you’re used to.
Oh wow, undici seems to be the crowd favorite! Gonna try that first.

Axios looks solid too, but I’m just making simple API calls, so undici might be perfect.

Thanks y’all—kinda wild how something as basic as fetch in nodejs needs a whole package, but hey, whatever works.

(Also, TIL why Node didn’t include it. Makes sense now!)



Users browsing this thread: 1 Guest(s)