Skip to content
TabBench

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

  1. Paste the curl command.
  2. Choose the library: fetch, XMLHttpRequest, Node.js https, jQuery or Axios.
  3. Adjust the style options (async/await or .then(), error handling, how the response is printed).
  4. Copy the code and read the notes for that runtime.
  5. 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?

fetch for new browser and Node 18+ code. The Node.js https version when you want no dependencies on older Node. XMLHttpRequest and jQuery mainly for legacy browser code.

Why does the Node.js https version not follow redirects?

The built-in http and https modules never follow redirects. Use fetch or Axios if you passed -L, or add a package such as follow-redirects.

Can I send a file upload with the https module?

Building multipart bodies by hand is error-prone, so for uploads the converter falls back to fetch with FormData, which Node.js 18 and later include.

Does the Node.js output need any packages?

No. It uses only the built-in https (or http) module. For uploads it switches to fetch, which Node.js 18 and later include.

Can I use the XMLHttpRequest output in Node.js?

No. XMLHttpRequest is a browser API. Use the fetch or https versions in Node.js.

Why is a header missing from the browser versions?

Browsers refuse to let scripts set certain headers. They are listed in the notes under the code and are left in the output so you can see them, but the browser ignores them.