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.
| Option | What curl does | JavaScript code |
|---|---|---|
-X, --request | Changes the method word, and only that | method: 'PUT' |
-H, --header | Adds a header; one with the name of a header curl would send replaces it | headers: {…} |
-d, --data | Sends a POST with Content-Type application/x-www-form-urlencoded; several are joined with &; @file reads a file and strips its line breaks | body: '…' and that Content-Type |
--data-raw | The same, but @ has no special meaning | As -d |
--data-binary | Sends the data "exactly as specified"; @file keeps line breaks | As -d; a file is read with Node.js's readFile |
--data-urlencode | Percent-encodes content, =content or the content of name=content | The encoded text in body |
--json | Sends 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, --get | Puts the data in the address as a query string and sends a GET | The query string in the address |
-u, --user | User name and password; Basic authentication is curl's default | 'Authorization': 'Basic ' + btoa('user:password') |
--oauth2-bearer | A bearer token | The same header |
-A, -e | User-Agent and Referer | Headers (see the notes on browsers) |
-b name=value | Cookies; without = it is a file to read cookies from | A Cookie header |
-I, --head | A HEAD request | method: 'HEAD' |
-k, --insecure | Skips the certificate check | Not converted: fetch has no such option |
-m, --max-time | The longest a transfer may take, in seconds | signal: AbortSignal.timeout(…) |
-x, --proxy | A proxy | Not converted: fetch takes no proxy |
-s, -v, -i, -w… | Change what curl prints | Left 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 @fileuses Node.js'sreadFile, which a browser does not have. - await. The code uses
awaitat 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.comwith 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-Gto 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.okorresponse.status, as the printed status line reminds you. - Redirects and timeouts. fetch follows redirects by default (
redirect"Defaults tofollow"), while curl follows them only with-L. For--max-time, the code passesAbortSignal.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.
-bwith a file name,-c(a cookie jar),-K(a config file),--data-urlencode name@file,-oand-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
$TOKENare 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:
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:
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:
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
-
1 credit
YouTube Search API
YouTube search results for a query, with the same sorting and filters the site offers.
GET /v1/youtube/search -
1 credit
Google Search API
The first page of Google results for a search: rank, title, link, domain, snippet and date of each result, plus related searches.
GET /v1/google/search -
1 credit
Web Page to Markdown API
The content of one web page as Markdown or text, without its menus, with title, headings and word and token counts.
GET /v1/web/content
Guides
Similar tools
More free tools
- Instagram engagement rate calculator
- TikTok engagement rate calculator
- YouTube engagement rate calculator
- X (Twitter) engagement rate calculator
- LinkedIn engagement rate calculator
- Facebook engagement rate calculator
- SRT to VTT converter
- VTT to SRT converter
- Subtitle file to plain text
- YouTube video ID finder
- YouTube timestamp link generator
- YouTube thumbnail downloader
- Email extractor
- HTML to Markdown converter
- X API cost calculator
- JSON to CSV converter
- CSV to JSON converter
- robots.txt tester
- Google search snippet preview
- Meta title and description length checker
- Instagram profile viewer
- Instagram profile picture viewer