
Paste a curl command and get working JavaScript. Choose fetch or axios, browser or Node.js, async/await or promise chains. The list under your command shows what each flag turned into.
How each part of the command was converted
Conversion happens in your browser. Your command, tokens, and passwords are never uploaded or sent anywhere.
How to convert a curl command to JavaScript
- Copy a curl command from API docs, Postman, or your browser's DevTools (right-click a request in the Network tab, then Copy > Copy as cURL).
- Paste it into the box above. Multi-line commands with
\or^line breaks work as-is. - Pick your setup: fetch or axios, browser or Node.js, and async/await or
.then(). - Check the notes under the code for anything that couldn't be carried over, then copy or download the result.
What gets converted, flag by flag
The converter reads curl's options the way curl itself does, including combined short flags like -sSL and attached values like -XPOST.
| curl flag | JavaScript result |
|---|---|
-X, --request | method option. When there's no -X, a body makes it POST, just like curl. |
-H, --header | An entry in the headers object. -H 'Name:' removes a header. |
-d, --data, --data-raw, --data-binary | body. JSON becomes JSON.stringify({...}), key=value pairs become new URLSearchParams(), anything else stays a string. |
--data-urlencode | The value is percent-encoded using curl's name=content rules. |
--json | A JSON body plus Content-Type and Accept headers set to application/json. |
-F, --form | A FormData object. @file fields read from a file input in the browser or from disk in Node. |
-u, --user | Authorization: Basic using btoa() for fetch, or axios's auth option. |
--oauth2-bearer | Authorization: Bearer header. |
-b, --cookie | A Cookie header in Node. In the browser, credentials: 'include', since browsers manage cookies themselves. |
-e, --referer | The referrer option in the browser, a Referer header in Node. |
-A, --user-agent | User-Agent header. |
-G, --get | Data is moved into the URL's query string. |
--url-query | Appended to the query string. |
-I, --head | A HEAD request that logs the status and response headers. |
-T, --upload-file | A PUT request with the file as the body. |
-m, --max-time | signal: AbortSignal.timeout(ms) for fetch, timeout for axios. |
-L, --compressed | Not needed. fetch follows redirects and decompresses responses on its own. |
-s, -v, -o, -i, -w | Skipped, because they only change what curl prints in the terminal. |
Example: curl POST to fetch
This curl command sends JSON to an API:
curl -X POST https://api.example.com/v1/users \
-H 'Content-Type: application/json' \
-d '{"name":"Ada Lovelace","role":"admin"}'Here is the fetch version using async/await:
const response = await fetch('https://api.example.com/v1/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
name: 'Ada Lovelace',
role: 'admin',
}),
});
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log(data);The response.ok check matters because fetch doesn't throw on 404 or 500 responses. It only rejects when the network request itself fails. curl behaves the same way unless you pass -f.
Browser vs. Node.js output
Browsers won't let JavaScript set certain headers, including Cookie, Host, Origin, Referer, and anything starting with sec-. Commands copied from Chrome DevTools are full of these. With Browser selected, the converter removes them and leaves a comment saying which ones. With Node.js selected, every header is kept, and file uploads read from disk with readFileSync.
Node.js 18 and newer include fetch, FormData, and Blob, so the Node output runs without installing anything. The axios output needs npm install axios.
Working in Python instead? Try the cURL to Python Requests converter.
Frequently asked questions
Is it safe to paste commands with API keys?
Yes. The converter is plain JavaScript running on this page. It doesn't make network requests, and nothing you paste is stored or sent to a server. You can disconnect from the internet after the page loads and it will keep working.
Why did my request fail with a CORS error?
curl doesn't follow browser security rules, but fetch in a browser does. If the API doesn't send Access-Control-Allow-Origin headers for your site, the browser blocks the response. The fix is on the server or through your own backend, which is also why the Node.js output often works where the browser version doesn't.
Does it support Chrome's "Copy as cURL (cmd)" format?
Yes. Windows cmd commands that use ^ for escaping and line breaks are detected automatically, along with bash-style \ continuations, PowerShell backticks, and $'...' quoting.
What happens to -k or --insecure?
There's no fetch option for skipping certificate checks. Browsers always verify certificates. In Node you can use a custom HTTPS agent with axios, or set NODE_TLS_REJECT_UNAUTHORIZED=0 for local testing only.
Should I use fetch or axios?
fetch is built into browsers and Node 18+, so it needs no dependencies. axios adds conveniences like automatic JSON parsing, throwing on HTTP errors by default, and request timeouts without an AbortSignal. Both produce the same request.
