How to convert curl to Node.js (axios)
- Paste your curl command (from API docs, a terminal or your browser's dev tools).
- The Node.js (axios) code appears instantly, using axios. Switch tabs to see other languages.
- Copy the code and run it after installing the library:
npm install axios.
How curl options map to axios
| curl | Node.js (axios) |
|---|---|
-X POST | method: "post" |
-H 'Name: value' | headers: {...} |
-d '{"json": true}' | data: {...} (sent as JSON) |
-F 'name=value' | data: FormData |
-u user:pass | auth: { username, password } |
-m 10 | timeout: 10000 |
-k | httpsAgent: 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.