Skip to content

curl to axios Converter

Paste a curl command and get Node.js code using axios: JSON bodies become plain objects, -u becomes axios's auth option, and -k becomes an HTTPS agent.
import axios from "axios";

const response = await axios({
  method: "post",
  url: "https://jsonplaceholder.typicode.com/posts",
  headers: {
    "Content-Type": "application/json",
    Authorization: "Bearer YOUR_TOKEN",
  },
  data: {
    "title": "Hello",
    "body": "From curl",
    "userId": 1
  },
});

console.log(response.data);

Converted in your browser. Commands often contain API keys, so nothing is sent anywhere or saved.

How to convert curl to Node.js (axios)

  1. Paste your curl command (from API docs, a terminal or your browser's dev tools).
  2. The Node.js (axios) code appears instantly, using axios. Switch tabs to see other languages.
  3. Copy the code and run it after installing the library: npm install axios.

How curl options map to axios

curlNode.js (axios)
-X POSTmethod: "post"
-H 'Name: value'headers: {...}
-d '{"json": true}'data: {...} (sent as JSON)
-F 'name=value'data: FormData
-u user:passauth: { username, password }
-m 10timeout: 10000
-khttpsAgent: new https.Agent({ rejectUnauthorized: false })

Tips for the generated Node.js (axios) code

  • Unlike fetch, axios throws for non-2xx responses. Read error.response.status and error.response.data in your catch block.
  • Set a timeout: axios has none by default.
  • For many calls to one API, create an instance with axios.create({ baseURL, headers }) and reuse it.

Convert curl to other languages

The same converter writes Python, JavaScript, Go, PHP and Ruby. See the cURL converter for every supported option.

Need an API to try it on? Every API in our list of APIs with no key works with a plain curl command.

Frequently asked questions

Does axios convert objects to JSON automatically?

Yes. When data is a plain object, axios serialises it to JSON and sets Content-Type: application/json. Strings are sent as-is, which is how the converter keeps form-encoded bodies exact.

How do I send multipart form data with axios in Node.js?

Node.js 18+ has a global FormData, and axios 1.x accepts it directly as data. For files, append a Blob of the file's contents with a filename, as in the generated code.

Should I use axios or fetch?

fetch is built in and has no dependencies. axios adds conveniences: automatic JSON, throwing on HTTP errors, timeouts, interceptors and upload progress. Both send the same requests.

How do I copy a request as cURL from Chrome?

Open DevTools (F12), go to the Network tab and reload. Right-click the request, choose Copy, then Copy as cURL (bash). Paste it here. Chrome's Windows (cmd) format works too.

Is it safe to paste commands that contain API keys?

Yes. The conversion runs entirely in your browser; nothing you paste is sent to a server, logged or saved. Still, rotate any key you've shared publicly.

More free developer tools