cURL to JavaScript fetch converter

Paste a curl command and get the same request as JavaScript fetch code, with a note for anything fetch cannot do. The command stays in your browser.

Example command: paste your own over it

JavaScript
  • Left out, because they only change what curl prints: -s.

Fetching web pages from JavaScript? The Web Page to Markdown API returns a page's content as Markdown, without its menus, in one request.

Free, no sign-up. It runs in your browser: what you type is not sent anywhere.

Checked on 2026-11-24.

How to convert curl to JavaScript

Paste the curl command into the box. The JavaScript appears underneath at once: one await fetch(…) call with the method, headers and body the command sends, then lines that print the status and the answer. Under it, a list of notes says what was left out and why. Copy the code, or download it as a .js file. The menu at the top switches the output to Python.

The command can be written for bash or zsh, with single quotes, double quotes, $'…' strings and lines continued with a backslash. A command written for the Windows command prompt, with ^ at the ends of lines and ^" around values, is read by that shell's rules instead, and a backtick at the end of a line, as PowerShell continues lines, is accepted too. The tool does not send the request and has no way to: it only rewrites the text, and your browser does all of it.

A request copied from a browser is a good start: in Chrome's developer tools, the Network panel's menu for a request has Copy as cURL. If the command carries cookies or an Authorization header, they let anyone who has the code act as you on that site, so keep the converted code as private as a password.

What each option becomes

The meaning of each option is taken from curl's manual (the version for curl 8.23.1), and the JavaScript uses the options of a fetch request as MDN describes them.

OptionWhat curl doesJavaScript code
-X, --requestChanges the method word, and only thatmethod: 'PUT'
-H, --headerAdds a header; one with the name of a header curl would send replaces itheaders: {…}
-d, --dataSends a POST with Content-Type application/x-www-form-urlencoded; several are joined with &; @file reads a file and strips its line breaksbody: '…' and that Content-Type
--data-rawThe same, but @ has no special meaningAs -d
--data-binarySends the data "exactly as specified"; @file keeps line breaksAs -d; a file is read with Node.js's readFile
--data-urlencodePercent-encodes content, =content or the content of name=contentThe encoded text in body
--jsonSends the data as it is, with Content-Type and Accept application/json (added in curl 7.82.0)body: JSON.stringify(…) and both headers
-G, --getPuts the data in the address as a query string and sends a GETThe query string in the address
-u, --userUser name and password; Basic authentication is curl's default'Authorization': 'Basic ' + btoa('user:password')
--oauth2-bearerA bearer tokenThe same header
-A, -eUser-Agent and RefererHeaders (see the notes on browsers)
-b name=valueCookies; without = it is a file to read cookies fromA Cookie header
-I, --headA HEAD requestmethod: 'HEAD'
-k, --insecureSkips the certificate checkNot converted: fetch has no such option
-m, --max-timeThe longest a transfer may take, in secondssignal: AbortSignal.timeout(…)
-x, --proxyA proxyNot converted: fetch takes no proxy
-s, -v, -i, -w…Change what curl printsLeft out

The body is written the way curl sends it. Form data stays a string, with the application/x-www-form-urlencoded Content-Type that curl adds for -d, so the server receives the same bytes. JSON becomes an object passed to JSON.stringify, which is easier to edit; if it holds a number with more digits than a JavaScript number keeps, such as a 20-digit id, the original text is sent instead, so the id arrives unchanged.

In a browser or in Node.js

The code runs in both, with some differences that come from fetch itself:

  • Node.js. fetch is built in: Node.js lists it as available without a flag since version 18 and no longer experimental since version 21 (Node.js globals). Reading a file for -d @file uses Node.js's readFile, which a browser does not have.
  • await. The code uses await at the top level, which works only "inside an async function or at the top level of a module" (MDN). Run it as a module, or put it inside an async function.
  • Headers a browser keeps for itself. In a browser, a script cannot set forbidden request headers such as Cookie, Referer, Host, Origin and Accept-Encoding; the tool names any of them your command has. MDN also notes that Chrome drops a User-Agent header from fetch requests.
  • A user name and password in the address. fetch refuses an address such as https://user:password@example.com with a TypeError (MDN), so the converter takes them out of the address and sends them as an Authorization header.
  • A body with GET or HEAD. curl sends data with -X GET -d …, but the Fetch Standard throws a TypeError when a GET or HEAD request has a body. The converter leaves the data out and says so; add -G to the command to send it in the address.
  • Errors. A fetch "does not reject if the server responds with HTTP status codes that indicate errors" (MDN): check response.ok or response.status, as the printed status line reminds you.
  • Redirects and timeouts. fetch follows redirects by default (redirect "Defaults to follow"), while curl follows them only with -L. For --max-time, the code passes AbortSignal.timeout(), which aborts the request with a TimeoutError after that many milliseconds.

What it does not convert

Each of these gets a note in the tool when your command uses it:

  • Options fetch has no place for. -k (skipping certificate checks), -x (a proxy) and --digest.
  • Multipart forms and uploads. -F (a multipart form, often with a file) and -T (a file upload) are not converted.
  • Files curl reads or writes. -b with a file name, -c (a cookie jar), -K (a config file), --data-urlencode name@file, -o and -O.
  • Connection details. Client certificates, --resolve, --connect-to, --retry, HTTP/2 and HTTP/3 options, rate limits and Unix sockets.
  • The shell. Variables such as $TOKEN are written as they are, not filled in, and only the curl command is read: anything after a pipe, ; or && is left out. curl's own globbing, {a,b} and [1-9] in an address, is not expanded.
  • Several addresses. Only the first is converted.

Get the data automatically

Every endpoint's reference page shows its request three ways: as curl, as JavaScript and as Python. The page content endpoint, for example, which returns one web page's content as Markdown or text, has this curl line:

Terminal
curl "https://pipefetch.com/v1/web/content?url=https%3A%2F%2Fdocs.apify.com%2Facademy" \
  -H "x-api-key: YOUR_API_KEY"

The same request in JavaScript, with the key read from the environment, a timeout, and the answers that cost nothing:

JavaScript
const url = new URL('https://pipefetch.com/v1/web/content');
url.searchParams.set('url', 'https://docs.apify.com/academy');

const res = await fetch(url, {
  headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY },
  signal: AbortSignal.timeout(90000),
});
if (res.status === 404) {
  const { error } = await res.json();
  console.log(error.code); // not charged
} else if (!res.ok) {
  throw new Error(`HTTP ${res.status}`);
} else {
  const { data } = await res.json();
  console.log(data.title, data.wordCount, 'words');
  console.log(data.content);
}

And in Python, with Requests:

Python
import os
import requests

res = requests.get(
    "https://pipefetch.com/v1/web/content",
    params={"url": "https://docs.apify.com/academy", "format": "markdown"},
    headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
    timeout=90,
)
if res.status_code == 404:
    # not_allowed, needs_javascript, no_content, page_not_found, website_blocked
    # or website_unreachable: not charged
    print(res.json()["error"]["code"])
else:
    res.raise_for_status()
    page = res.json()["data"]
    print(page["title"], page["wordCount"], "words")
    print(page["content"])

Pasted here, that line gives the same request with the key written into the code; in a script, read it from the environment instead, as above. A request costs 1 credit, and none of the 404 answers costs anything. The page is read as plain HTML without running JavaScript, so a page that builds its text in the browser comes back with needsJavaScript true.

Questions

Is my curl command sent anywhere?

No. The command is turned into JavaScript by this page, in your browser, and the request in it is never made. Nothing you paste leaves the page, which matters because a copied command often holds a token, a password or session cookies.

Does the code work in Node.js?

Yes. fetch is built into Node.js without a flag since version 18. The code uses await at the top level, which works in a module; elsewhere, put it inside an async function.

Why does the browser not send my Cookie header?

Cookie is a forbidden request header: in a browser, a script cannot set it, and the browser decides which cookies to send. MDN lists the other headers like it.

How do I set a timeout?

Pass signal: AbortSignal.timeout(milliseconds) in the options. The converter does that when the command has --max-time.

Why does fetch not throw on a 404?

A fetch only fails on a network error or a bad request; an error status from the server is an ordinary response. Check response.ok or response.status.

Why is -k not converted?

fetch has no option to skip certificate checks, so the code checks the certificate as usual, and the tool says so in a note. With a server whose certificate is not valid, the request then fails.

Need this for many accounts, or in your code? The Pipefetch API returns the data as JSON, one GET request at a time. Get an API key with 100 free credits, no card needed.

APIs that return this data

Guides

Similar tools

More free tools

All free tools