cURL to JavaScript Converter
Paste a curl command and get JavaScript code in your choice of fetch, XMLHttpRequest, the Node.js https module, jQuery $.ajax or Axios.
Runs in your browser. Nothing you add is uploaded.
What the cURL to JavaScript Converter does
“JavaScript” means several different things for HTTP: the modern fetch API, the older XMLHttpRequest, Node.js's built-in https module, jQuery's $.ajax and libraries such as Axios. This converter takes one curl command and writes the version for whichever you use, and explains what differs. Paste a command, pick the style and get code you can drop into a browser script, a Node.js file or a legacy page.
How to convert curl to JavaScript
- Paste the curl command.
- Choose the library: fetch, XMLHttpRequest, Node.js https, jQuery or Axios.
- Adjust the style options (async/await or .then(), error handling, how the response is printed).
- Copy the code and read the notes for that runtime.
- Run it in the browser console, a script tag or with node file.js, depending on the style.
The cURL to JavaScript Converter runs entirely in your browser — nothing you enter is uploaded, stored, or logged.
When to use it
Supporting an older browser code base
Legacy sites still use XMLHttpRequest or jQuery. Generate code in the same style as the rest of the project.
Zero-dependency Node.js scripts
The https module needs no install. The output includes a Content-Length header and handles the response stream for you.
Comparing approaches
Switch between the styles with the same command to see how each one expresses headers, bodies and errors.
Good to know
- Prefer fetch in new code: it is standard, promise-based and needs no dependency.
- XMLHttpRequest reports network errors through onerror and HTTP errors through the status code.
- jQuery needs processData: false and contentType: false to send FormData.
- The Node.js https module buffers nothing for you: collect the chunks, then parse.
- Set a timeout in every style, because HTTP requests can hang.
Frequently asked questions
Which JavaScript output should I use?
Why does the Node.js https version not follow redirects?
Can I send a file upload with the https module?
Does the Node.js output need any packages?
Can I use the XMLHttpRequest output in Node.js?
Why is a header missing from the browser versions?
Related tools
cURL Command Generator
Build a correct curl command from a form, for any shell.
HTTP Status Code Lookup
Look up any HTTP status code: meaning, causes and how to fix it.
HTTP Header Analyzer
Paste HTTP headers to see what each means and what to fix.
HTTP Header Generator
Generate security, CORS, cache and CSP headers for your server.