cURL to axios is a free converter that turns cURL commands into Node.js code using axios. Headers, JSON data, URL-encoded forms, multipart uploads, basic auth and TLS settings are converted. It runs in your browser, so secrets in the command stay on your device.
How to convert cURL to axios
- Paste the cURL command.
- Copy the generated code.
- Install axios with
npm install axiosand run it with Node.js (as an ES module, e.g. a.mjsfile).
From API docs to a Node.js service
API providers usually document their endpoints with cURL examples. Converting them to axios gives you a starting point for a Node.js backend, script or serverless function. Move tokens such as Bearer keys into environment variables (process.env.API_KEY) before committing the code.
How options are translated
- JSON bodies are passed as a JavaScript object in
data; axios serialises it and sets the Content-Type. - URL-encoded forms (
-d a=1&b=2) useURLSearchParams. - -u uses axios’s
authoption. - No -L sets
maxRedirects: 0, matching curl’s default of not following redirects. - -k creates an HTTPS agent that skips certificate checks, for testing only.
Handling errors
axios throws for any 4xx or 5xx response. Wrap the call in try/catch and readerror.response.status and error.response.data to see what the API said.
Prefer the browser’s built-in API? The same command converts to JavaScript fetch, which needs no library, or to Python Requests. If the request sends Basic authentication, the Basic Auth Header Generator shows the username and password inside the header.
Frequently asked questions
Is it safe to paste commands with tokens or passwords?
Yes. The command is converted inside your browser and never sent anywhere. Still, remember to remove real secrets before sharing the generated code with others.
How is curl -k handled?
It becomes an https.Agent with rejectUnauthorized: false, which skips certificate checks just like -k. Only use it for testing; never in production.
How are file uploads converted?
-F name=@file becomes a FormData field that reads the file with fs.createReadStream.
Do I need to install anything?
Yes: npm install axios. The rest uses Node.js built-ins.
Last updated