How to use fetch in Node.js? Getting 'fetch is not defined' error Alternatively, if you want something more

12 Replies, 1218 Views

Ugh, this tripped me up too. If you’re on Node 18+, fetch in nodejs *is* actually supported… but only behind a flag or in experimental mode.

Try running your script with:
`node --experimental-fetch yourfile.js`

Otherwise, yeah, node-fetch or axios are the go-tos.

Fun fact: the nodejs team is working on native fetch support, so maybe soon we won’t need workarounds!

Messages In This Thread



Users browsing this thread: 1 Guest(s)