Why isn't fetch in Node.js working like it does in the browser? or What's the best way to use fetch i

16 Replies, 1529 Views

ohhhh this is a rite of passage for node devs. fetch in nodejs wasn’t a thing until Node 18, so you’ve got options:

1. Upgrade to Node 18+ (easiest if you can).
2. `npm install node-fetch` (but v3+ needs ESM, so maybe v2).
3. Use undici (`npm install undici`)—it’s the engine behind node’s fetch.

axios is chill too, but fetch is legit once you sort the setup.

Messages In This Thread



Users browsing this thread: 1 Guest(s)