Convert cURL to Node.js (fetch)
Paste a curl command to get the same request as Node.js fetch code, with no packages to install. Below the converter, each flag is shown with the exact lines it adds, and the transfer options fetch handles differently from curl are spelled out.
What each curl flag becomes in Node.js fetch
Each example below is the converter's real output, generated when this page was built, from the same code the box above runs. Only the lines a flag adds are shown, compared with converting a bare curl URL, so you can see exactly where each piece of the command lands in Node.js.
-H · Request headers
curl
curl https://api.example.com/items -H "Accept: application/json" -H "X-Request-Id: 42"
Lines it adds to the Node.js fetch code
headers: {
"Accept": "application/json",
"X-Request-Id": "42",
},
--json · A JSON body
--json is curl shorthand for a body plus both Content-Type: application/json and Accept: application/json, so both headers appear.
curl
curl https://api.example.com/items --json '{"name":"widget","qty":2}'
Lines it adds to the Node.js fetch code
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: "{\"name\":\"widget\",\"qty\":2}",
-d · A form body
Two -d flags join with &, any -d makes the request a POST, and curl labels the body application/x-www-form-urlencoded unless you set a Content-Type yourself.
curl
curl https://api.example.com/login -d "user=ada" -d "remember=1"
Lines it adds to the Node.js fetch code
method: "POST",
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
body: "user=ada&remember=1",
-G · Data sent as query parameters
-G moves the data into the URL and sends a GET with no body and no Content-Type, which is what curl puts on the wire.
curl
curl -G https://api.example.com/search --data-urlencode "q=café au lait"
Lines it adds to the Node.js fetch code
const url = "https://api.example.com/search?q=caf%C3%A9+au+lait";
-u · Basic authentication
-u becomes an Authorization: Basic header with the base64 of user:password. If the command also sets its own Authorization header, that header wins, as it does in curl.
curl
curl -u ada:s3cret https://api.example.com/me
Lines it adds to the Node.js fetch code
headers: {
"Authorization": "Basic YWRhOnMzY3JldA==",
},
-b · Cookies
curl
curl -b "session=abc123; theme=dark" https://api.example.com/me
Lines it adds to the Node.js fetch code
headers: {
"Cookie": "session=abc123; theme=dark",
},
-F · A multipart upload
curl
curl https://api.example.com/upload -F "title=Q3 report" -F "file=@report.pdf"
Lines it adds to the Node.js fetch code
const form = new FormData();
form.append("title", "Q3 report");
import { readFile } from "node:fs/promises";
form.append("file", new Blob([await readFile("report.pdf")]), "report.pdf");
…
const response = await fetch(url, {
method: "POST",
body: form
});
The converter also notes: a -F upload needs Content-Type: multipart/form-data with a boundary generated per request, so the target language sets that header itself.
-X · A different method
curl
curl -X DELETE https://api.example.com/items/7
Lines it adds to the Node.js fetch code
method: "DELETE",
-I · A HEAD request
curl
curl -I https://api.example.com/health
Lines it adds to the Node.js fetch code
method: "HEAD",
What the generated code does not carry over
Some curl flags change how the transfer behaves rather than what the request is, and the converter leaves them out. For each flag below, this build checked that adding it leaves the Node.js fetch output unchanged, then noted what fetch does by default and how to match curl:
-L: Nothing to add: fetch follows redirects by default. A command without-Lstops at the 3xx response; to reproduce that, passredirect: "manual", and Node returns the redirect response itself.--compressed: Nothing to add: Node's fetch sendsAccept-Encoding: gzip, deflateand decodes the response on its own.-k: fetch has no per-request switch for this. SettingNODE_TLS_REJECT_UNAUTHORIZED=0in the environment turns certificate checking off for the whole process, and Node warns you when you do; use it only against a test server.-m 10: Addsignal: AbortSignal.timeout(10000)to the options object. fetch has no timeout option of its own.
More from cURLParse
Guides
Frequently Asked Questions
Does the generated Node.js code need axios or any other package?
No. It uses the fetch built into Node.js 18 and later, so there is nothing to install. Run it as an ES module, in a .mjs file or with type set to module in package.json, because it uses await at the top level.
How do I make fetch stop at a redirect the way curl does?
Pass redirect: 'manual' in the options. fetch follows redirects by default, while curl only does with -L. In Node.js, manual mode returns the redirect response itself, so you can read its status and Location header.