Skip to content
koducathome

cURL to Node.js node-fetch Converter

Convert curl commands to Node.js code using node-fetch. Paste a command and the node-fetch snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Node.js node-fetch code appears instantly; other Node.js libraries (fetch (built-in), Axios, Got, Ky, request, SuperAgent, http) are in the tabs above the code.
  3. Set up: Install with npm install node-fetch.
  4. Run it: Save as request.mjs and run node request.mjs. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no node-fetch equivalent.

Example

GET with headers → Node.js node-fetch

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Node.js node-fetch
import fetch from 'node-fetch';

const response = await fetch('https://api.example.com/v1/users?page=2', {
  headers: {
    'Accept': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN'
  }
});

console.log(response.status);
console.log(await response.json());

Common use cases

  • Older Node.js versions
  • Projects that already depend on node-fetch

Converting curl to Node.js node-fetch

The node-fetch package brings the Fetch API to Node.js versions without built-in fetch. Version 3 is ES-module only.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent node-fetch code. Options that have no node-fetch equivalent are listed under the editors rather than silently dropped.

Other libraries for Node.js, each with its own page: fetch (built-in), Axios, Got, Ky, request, SuperAgent, http.

Limitations

  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Do I still need node-fetch?

Not on Node.js 18+, which has built-in fetch. Use it for older Node versions or existing code.

Why does require('node-fetch') fail?

node-fetch v3 is ES-module only. Use import, or install v2 for CommonJS.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.