cURL to JavaScript — Convert cURL Commands to JavaScript
Convert cURL commands to JavaScript fetch() calls. Browser and Node.js variants, runs entirely in your browser. No uploads, no accounts, no limits.
cURL to JavaScript
Convert cURL commands to JavaScript fetch code. Works entirely in your browser — no uploads.
cURL to JavaScript is the most-used conversion in this family, because JavaScript is the only language that runs natively in every browser and is the most common target for "let me just test this API once" scripts. The cURL command is the lingua franca for "here is how to make this HTTP request" — exported from DevTools, copied from API docs, pasted from shell history — and the conversion to JavaScript is the shortest path from "I see the request in my terminal" to "I can run this in a browser console or a Node.js REPL". The fetch() API is the modern standard for both runtimes and the output here is a single async function you can paste anywhere.
The non-obvious thing about cURL-to-JavaScript is the runtime split. The same fetch(url, options) call works in both the browser and Node.js, but the surrounding code is different: browsers have fetch built in (no import needed), while Node.js needs the undici package or the built-in fetch on Node 18+. The tool’s runtime toggle switches between these — the browser output is just the fetch call wrapped in an async function, the Node.js output adds the import or uses the global fetch directly. Both outputs are minimal and idiomatic, with no third-party dependencies required.
For a final hand-off: if the goal is a one-off test in the browser console, copy the browser-runtime output and paste it directly. If the goal is a Node.js script, copy the Node.js output and add the necessary imports. If the goal is a production code path, the output is a starting point — add error handling for non-2xx status codes, add response.json() parsing if the endpoint returns JSON, and consider using AbortController for request cancellation in long-running pages or scripts. The tool here gives you a working baseline in seconds; production hardening is the next step.
How to use
Paste a cURL command
Copy a cURL command from browser DevTools (Network tab > Copy as cURL), a documentation page, or your shell history. The parser handles `-H`, `-d`, `-X`, `-u`, `--cookie`, and other common flags.
Pick a runtime
Choose between the browser fetch API (works in any modern browser, no dependencies) and Node.js with the `node-fetch` or `undici` package (for server-side use). The output is the same `fetch(url, options)` call in both cases.
Customize the output
The default output is async/await with a single response handler. Toggle the option to add response.json() parsing, error handling for non-2xx status codes, or to wrap the call in an immediately-invoked function expression.
Frequently asked
Which runtime should I pick?
Browser fetch is the right pick for any client-side code (a React component, a Vue app, a vanilla JS page). Node.js fetch is the right pick for server-side code, scripts, and CLI tools. The fetch API shape is identical; only the surrounding code (imports, top-level await) differs.
Does it work with the older XMLHttpRequest API?
No — the output uses `fetch()`, which is the modern standard. For legacy code that requires `XMLHttpRequest`, manually adapt the output. The fetch API has been supported in every browser since 2015 and in Node.js since v18.
How are headers passed to fetch?
Headers from cURL's `-H` flags become a `headers` object in the fetch options: `headers: { 'Content-Type': 'application/json', 'Authorization': 'Bearer ...' }`. The Content-Type is set automatically when a body is present.
What about cookies and authentication?
`-b 'name=value'` becomes a `Cookie` header. `-u 'user:pass'` becomes a basic-auth header. Cookies set by the server are stored by the browser automatically (in browser fetch) or require an explicit `Cookie` header in Node.js with the `cookie` package.
Will the generated code handle errors?
The default output is a single `fetch()` call without error handling. Toggle the 'include error handling' option to wrap the call in a try/catch that throws on non-2xx status codes, with a helper that reads the response body for the error message.
Limitations
- No streaming responsesThe output uses `response.json()` for the response body, which loads the entire body into memory. For streaming responses (server-sent events, chunked transfer), use the underlying `response.body` ReadableStream with a custom reader.
- No automatic JSON parsingThe default output does not call `response.json()`. Toggle the option to add the call, or add it manually in your code. Without the call, the response is a `Response` object and you need to choose `.text()`, `.json()`, or `.blob()` yourself.
- Multipart uploads need manual workMultipart form uploads (`-F`) are supported but require constructing a `FormData` object in JavaScript. The output emits the FormData setup; for file uploads, add the file references (`formData.append('file', fileInput.files[0])`) yourself.
Platform notes
- macOS
- Browser fetch works in Safari, Chrome, and Firefox without configuration. For Node.js scripts, Node 18+ has fetch built in; earlier versions need `npm install node-fetch` and a `require()` line the tool does not add.
- Windows
- Browser fetch works in Edge, Chrome, and Firefox without configuration. For Node.js scripts in a Windows terminal, the fetch import and top-level await behavior matches Linux and macOS — no platform-specific gotchas.
- Linux
- Browser fetch works in every Linux browser. For Node.js scripts, the tool emits the standard `fetch()` call. Server-side fetch needs the `--experimental-fetch` flag on Node 16 and 17, but works out of the box on Node 18+.
- CLI
- The same library that powers this tool is available as the `curlconverter` package on npm, with a `curlconverter --language javascript` CLI mode. Useful for embedding in build scripts or for batch conversion of saved cURL commands.
- Web
- Runs entirely client-side. Works offline once the page has loaded. The generated JavaScript is portable — paste it into any browser script tag, a Node.js module, or a serverless function handler.