// Before Node 18 (and 17.5 experimental) const fetch = require('node-fetch'); // After Node 18 async function getData() const res = await fetch('https://api.example.com/data'); const data = await res.json(); console.log(data);
Let's look under the hood. 1. Native Fetch API (No More node-fetch ) For years, making an HTTP request in Node meant one of two things: installing node-fetch or using axios . It felt archaic that the runtime didn't include the same fetch your browser had. node 18
Thank Node 18 for fetch , streams, and a built-in test runner. Then leave it behind. What version of Node are you running in production right now? Let us know in the comments below. // Before Node 18 (and 17