Node v18 and on come with native Fetch API support built right into Node itself. No need for third party libraries, imports, requires, or small hand-crafted shims, just use global fetch the way you're used to from the browser.
const fs = require(`fs`); // As per the note above: remove the following line for Node 18 and above const fetch = require(`./that-code-shown-above.js`); fetch(`https://placekittenplacecats.com/20000/300`) .then(res => res.arrayBuffer()) .then(bytes => fs.writeFileSync(`kitten.jpg`, new Uint8Array(bytes))) .catch(e => console.error(e)); try { const response = await fetch(`https://jsonplaceholder.typicode.com/todos/1`); const data = await response.json(); console.log(data); } catch (e) { console.error(e); } // etc.