Skip to content
koducathome

cURL to Node.js http Converter

Convert curl commands to Node.js code using http. Paste a command and the http snippet appears instantly — everything runs in your browser.

How to use this tool

Steps for using the cURL to Code.

  1. Copy a curl command — from API documentation, or from your browser's DevTools (Network tab → right-click a request → Copy as cURL (bash)).
  2. Paste it into Enter cURL command. The Node.js http code appears instantly; other Node.js libraries (fetch (built-in), Axios, Got, Ky, node-fetch, request, SuperAgent) are in the tabs above the code.
  3. Set up: Nothing to install.
  4. Run it: Save as request.mjs and run node request.mjs. Replace placeholders such as YOUR_TOKEN first, and check any notes under the editors for curl options that have no http equivalent.

Example

GET with headers → Node.js http

curl command
curl 'https://api.example.com/v1/users?page=2' \
  -H 'Accept: application/json' \
  -H 'Authorization: Bearer YOUR_TOKEN'
Node.js http
import https from 'node:https';

const options = {
  method: 'GET',
  headers: {
    'Accept': 'application/json',
    'Authorization': 'Bearer YOUR_TOKEN'
  }
};

const req = https.request('https://api.example.com/v1/users?page=2', options, (res) => {
  let data = '';
  res.setEncoding('utf8');
  res.on('data', (chunk) => {
    data += chunk;
  });
  res.on('end', () => {
    console.log(res.statusCode, data);
  });
});

req.on('error', (err) => {
  console.error(err);
});
req.end();

Common use cases

  • Zero-dependency scripts
  • Full control over streaming and sockets

Converting curl to Node.js http

Node's built-in http/https modules are the lowest-level way to make requests, with no dependencies.

The converter reads the curl command the way curl does — the method (-X), headers (-H), request bodies (-d, --data-raw, --json, -F), query strings, basic auth (-u) and cookies — and writes the equivalent http code. Options that have no http equivalent are listed under the editors rather than silently dropped.

Other libraries for Node.js, each with its own page: fetch (built-in), Axios, Got, Ky, node-fetch, request, SuperAgent.

Limitations

  • Verbose — fetch or a client library is simpler for most code.
  • The code is a starting point: add timeouts, retries and error handling for production use.
  • Secrets in the curl command are copied into the code — move them to environment variables before committing.

Frequently asked questions

Why set Content-Length manually?

The low-level module doesn't calculate it, so the code uses Buffer.byteLength(body).

When should I use the http module?

When you need no dependencies or low-level control. Otherwise built-in fetch is simpler.

Is my curl command sent to a server?

No. The conversion runs entirely in your browser, so tokens and passwords in the command never leave your device. Still, replace real secrets before sharing the generated code.