Convert curl to Node.js

Convert curl commands to Node.js code using the built-in http module. curl2code runs entirely in your browser via WebAssembly — your API keys and data stay private. For browser-side JavaScript, see our curl to JavaScript converter. If you prefer Python, try curl to Python. Below you'll find ready-to-use examples.

How to copy curl from your browser

  1. 1

    Open DevTools

    Press F12 or Ctrl+Shift+I to open your browser developer tools.

  2. 2

    Go to the Network tab

    Click the Network tab and perform the action that triggers the HTTP request.

  3. 3

    Copy as cURL

    Right-click the request → CopyCopy as cURL. Then paste it above.

Frequently Asked Questions

What is Node.js http module?

The http and https modules are Node.js built-in modules for making HTTP requests without any dependencies. They provide low-level control over request/response streams. For higher-level alternatives, curl2code also supports axios, node-fetch, got, ky, and superagent.

http vs axios vs node-fetch vs got — which should I use?

http is zero-dependency but verbose. axios offers a clean API with interceptors and automatic JSON parsing. node-fetch mirrors the browser Fetch API. got is feature-rich with retries, pagination, and streams. Choose based on project needs. For browser JavaScript, see our curl to JavaScript converter.

How to handle authentication in Node.js?

Set the Authorization header in the options object. For Basic auth, use Buffer.from(user + ':' + pass).toString('base64'). With axios, use the built-in auth config option. curl2code converts -u and Bearer token flags for all supported Node.js libraries.

How to send multipart form data in Node.js?

With the built-in http module, construct the multipart body manually or use the form-data package. With axios, pass a FormData instance as the body. Node.js 18+ has a built-in FormData class. curl2code handles -F flags for each library variant.

How to handle HTTP errors in Node.js?

With http, listen for the 'error' event on the request and check response.statusCode. With axios, errors are thrown for non-2xx status codes and can be caught in try/catch. With got, use the same pattern plus built-in retry logic on failure.

How to handle streaming responses in Node.js?

The http module returns a readable stream by default — pipe it with response.pipe(fs.createWriteStream('file')). With got, use got.stream(url). With axios, set responseType: 'stream'. Streaming is ideal for large files and avoids loading entire responses into memory.

How to set timeouts in Node.js HTTP requests?

With http, pass timeout in options and listen for the 'timeout' event, then call req.destroy(). Axios accepts timeout in milliseconds. Got supports both timeout.request and built-in automatic retries with configurable backoff.

How to use a proxy with Node.js?

The built-in http module requires manual proxy tunneling. Use https-proxy-agent or http-proxy-agent packages. Axios supports proxies via proxy config. Got uses agent option with proxy agents. curl2code converts -x and --proxy flags appropriately.

How to send a POST request with JSON body in Node.js?

Convert a curl POST command like curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' URL to Node.js using curl2code. The generated code uses axios.post(url, { key: 'value' }). curl2code automatically detects -d/--data flags with JSON content and sets the appropriate Content-Type header in the axios code.

How to add Bearer token authorization in Node.js?

Pass curl -H "Authorization: Bearer YOUR_TOKEN" URL to curl2code and it generates axios code with the auth header: headers: { Authorization: 'Bearer YOUR_TOKEN' }. curl2code detects Bearer tokens from both -H "Authorization: Bearer ..." and --oauth2-bearer flags. For Basic auth, use -u user:pass.

How to set Content-Type header in Node.js?

curl2code converts curl -H "Content-Type: application/json" URL to axios code with the proper header: headers: { 'Content-Type': 'application/json' }. For -d data, curl defaults to application/x-www-form-urlencoded; for -F form uploads, it uses multipart/form-data. curl2code maps each to the correct axios API.

Useful Links

curl Guides

Convert curl to Other Languages