
node-fetch Has a Free API — Here's How to Use the Fetch Standard in Node.js
node-fetch brings the Fetch API to Node.js. While Node 18+ has built-in fetch, node-fetch remains relevant for older versions and offers additional features like custom agents and AbortController integration. Installation npm install node-fetch Basic Usage import fetch from " node-fetch " ; // GET request const response = await fetch ( " https://api.github.com/users/node-fetch " ); const data = await response . json (); console . log ( data ); // POST with JSON const result = await fetch ( " https://httpbin.org/post " , { method : " POST " , headers : { " Content-Type " : " application/json " }, body : JSON . stringify ({ tool : " node-fetch " , version : 3 }) }); console . log ( await result . json ()); Handling Streams import { createWriteStream } from " node:fs " ; import { pipeline } from " node:stream/promises " ; const response = await fetch ( " https://example.com/large-file.zip " ); if ( ! response . ok ) throw new Error ( `HTTP ${ response . status } ` ); await pipeline ( resp
Continue reading on Dev.to Webdev
Opens in a new tab

