Luciano Mammino’s Post

Confession: my fingers still type `npm i axios` on autopilot from time to time 😅 And yet… Node.js has shipped a built-in `fetch()` since v18 (2022)... Still, I keep running into the same questions: should we use it, when is it a good fit, and how do we avoid the usual footguns? That’s why I decided to write a detailed blog post about it. It’s a practical guide to using `fetch()` in Node.js without getting surprised in production. As usual, it’s written in my beginner-friendly style. I don’t assume you already know the tricky bits. I tell you upfront what can bite you, and what you can do about it. Here’s what it covers: • when to use `fetch()` vs the built-in `http`/`https` modules (and when you might still have to pick the latter) • why `await fetch(url)` only gives you a `Response`, not the body, and how to properly read JSON, text, bytes, and streams • timeouts (no more forever-pending requests) • retries + backoff • safe query params (goodbye string concatenation) • streaming requests (uploads) & streaming responses (downloads) • mocked requests with undici’s MockAgent + `node:test` If you’re writing Node services, CLIs, scrapers, or anything that talks to APIs, this should save you some pain 👇 https://lnkd.in/deChkZ44 Feedback and comments are very welcome. I’d love to hear what you’d add or do differently. What’s your default HTTP client in 2026: built-in `fetch()`, `http`/`https`, axios, got, ry, something else entirely? #nodejs #javascript #backend #webdev #testing

  • Cartoon illustration in flat colors: a smiling developer in a blue hoodie points upward while holding a green “Node.js FETCH GUIDE” book. Above him, speech bubbles read “npm axios”, “http/https”, and “fetch()” with a question mark. On the right, a cool turtle wearing sunglasses rides a rocket labeled “V8”; a checklist and stopwatch sit on the desk against a soft, patterned sky background.

When I started with Nodejs back in 2011 "request" library just became the most popular library to do HTTP request with a lot of features built in. I stopped using Nodejs at work in 2018. I started with Nodejs again in 2022 for side projects and later clients, "request" now is deprecated but there's now experimental "fetch" built-in which was just good enough. I've been using since then! It's amazing how far the Nodejs ecosystem have come.

Eugen Serbanescu

I build software teams and products

3mo

Excellent guide! It's very in depth and covers a lot of stuff which many people don't even think about (like back-off retry). I love that you mentioned when to use libraries, and the http & https modules, since they all have their place and their uses.

Grazie! I was just talking about fetch today trying to remember if it handled network errors or HTTP errors or both.

See more comments

To view or add a comment, sign in

Explore content categories