FormatterHQ

cURL to Axios (Node.js) Converter

Paste a curl command to get a Node.js axios request with a clean config object: params, headers, data, auth and timeout split out for you.

Input SHELL
Output JAVASCRIPT
Ready.

How to use the cURL to Axios (Node.js) Converter

  1. Paste the curl command into the input box.
  2. The axios code is generated automatically; click Convert after editing.
  3. Install the dependencies with npm install axios (and form-data for uploads).
  4. Save the output as an .mjs file and run it with node.

Convert curl to axios for Node.js

This curl to axios converter rewrites a curl command as a single axios({...}) call for Node.js. Instead of copying the full URL and a raw body string, it splits the request into the fields axios expects: url, params for the query string, headers, data, auth and timeout. The result uses ES module imports and top-level await.

Example: file upload with -F

For curl -F 'title=Q3 report' -F 'file=@report.pdf' -H 'X-Api-Key: YOUR_KEY' -L https://api.example.com/uploads you get:

import axios from 'axios';
import fs from 'node:fs';
import FormData from 'form-data';

const form = new FormData();
form.append('title', 'Q3 report');
form.append('file', fs.createReadStream('report.pdf'));

const response = await axios({
  method: 'post',
  url: 'https://api.example.com/uploads',
  headers: {
    ...form.getHeaders(),
    'X-Api-Key': 'YOUR_KEY',
  },
  data: form,
});

The form-data package streams the file from disk, and form.getHeaders() supplies the multipart Content-Type with its boundary.

How curl maps to the axios config

  • Query string: ?page=2&sort=name is moved into a params object, which axios encodes for you. When a key repeats (?tag=a&tag=b), the full URL is kept and no params object is written.
  • JSON body: when the Content-Type is application/json and the body parses, data becomes a JavaScript object and the redundant Content-Type header is dropped, because axios sets it automatically for objects.
  • Other bodies: form-encoded or plain text data stays a string in data.
  • Basic auth: -u user:pass becomes auth: { username, password }.
  • Timeout: --max-time 30 is converted to milliseconds, timeout: 30000.
  • Redirects: axios follows redirects in Node by default, so maxRedirects: 0 is added when the command has no -L.
  • TLS: -k adds an httpsAgent with rejectUnauthorized: false. Use it only for local testing.

Working with the axios response

curl prints the body and stops; with axios you get a response object to work with. The most useful parts:

console.log(response.status);                   // 200
console.log(response.headers['content-type']);  // header names are lowercase
console.log(response.data);                     // JSON is already parsed

Two adjustments are common after converting:

  • Downloading a file (what curl -o does): add responseType: 'stream' to the config and pipe response.data into fs.createWriteStream('out.zip'). Without it, binary data is decoded as text and corrupted.
  • Keeping 4xx and 5xx responses instead of catching them: add validateStatus: () => true, then check response.status yourself, which is closer to how curl behaves.

Limitations

The output targets Node.js. In a browser, httpsAgent, maxRedirects and the form-data package do not apply; use the native FormData and let the browser handle redirects. Proxy flags and client certificates are not converted, and unsupported options are listed as comments above the code. Keep in mind that axios rejects the promise for non-2xx status codes, so wrap the call in try/catch and read error.response for API errors.

Privacy

Everything is converted in your browser, so API keys in the command stay on your device. Prefer the built-in fetch? Use curl to JavaScript. To test the request before writing code, try the API tester, and generate typings for the response with JSON to TypeScript.

Frequently asked questions

Can I use the generated axios code with CommonJS require?
Yes. Replace the imports with const axios = require('axios') and wrap the call in an async function, because top-level await only works in ES modules.
Why did the Content-Type header disappear?
For JSON bodies the converter passes a plain object as data, and axios sets Content-Type: application/json for objects automatically. Other Content-Type values are kept unchanged.
Does the output work in the browser?
The core axios({...}) call does, but the Node-specific parts do not. Remove httpsAgent and maxRedirects, and use the browser's native FormData with a File object instead of fs.createReadStream.
Why does axios throw on a 404 when curl did not?
curl prints any response, while axios rejects the promise for status codes outside 2xx by default. Catch the error and inspect error.response.status, or pass validateStatus: () => true to resolve on every status.

Last updated October 3, 2026

Related tools

cURL to C# Converter Convert curl commands to C# HttpClient code for .NET with headers, content types, basic auth, multipart and TLS options. cURL to Go Converter Convert curl commands into Go code using net/http — method, headers, JSON or form body, basic auth, timeouts and multipart uploads. cURL to PHP Guzzle Converter Convert curl commands to PHP Guzzle requests using json, form_params, multipart, query and auth options. cURL to Java Converter Convert curl commands to Java 11+ java.net.http.HttpClient code with headers, body, redirects and timeouts. cURL to JavaScript Fetch Convert curl commands into JavaScript fetch() code with method, headers, JSON body, form data, basic auth and timeouts. cURL to PHP Converter Convert curl commands into PHP code using the curl_* functions: method, headers, body, auth, cookies and SSL options. cURL to Python Requests Convert curl commands into Python requests code: headers, params, JSON or form data, files, cookies, auth and timeouts. cURL to Rust Converter Convert curl commands to Rust using the reqwest crate, with JSON bodies via serde_json, headers, auth and timeouts. Date & Time Calculator Calculate the difference between two dates or add/subtract days, weeks, months and years from a date. Docker Run to Docker Compose Convert one or more docker run commands into a docker-compose.yml: ports, volumes, env, restart, networks, healthchecks and more. File Type Checker Find out what a file really is from its content, not its name. Detects 150+ formats and warns when the extension does not match. HTTP Status Codes Searchable list of the HTTP status codes in use, from 100 to 511, with a plain explanation of when each response is used.