Advertisements

headerup to 320x100 / 728x90

curl to Node.js Converter

Convert a curl command into Node.js https module code ready to paste into scripts or CI

Input
Loading editor...
Output

Output will appear here...

Advertisements

content bottomup to 300x250

What is curl to Node.js Converter

Last reviewed:

JavaScript is the programming language of the web, running in every modern browser and powering most interactive frontends and Node.js backends.

curl to Node.js Converter parses your curl command and produces an equivalent Node.js snippet using the built-in `node:https` module, including URL parsing, header setup, body writes, and basic error handling.

It's ideal when you need a portable Node script that doesn't depend on fetch (e.g. on Node < 18) or on third-party HTTP libraries.

Why use it

  • Support legacy Node runtimes without fetch().
  • Keep scripts dependency-free (no axios / node-fetch).
  • Port curl-based CI steps into Node scripts.
  • Teach Node HTTP fundamentals from a familiar starting point.
  • Debug TLS / header issues with explicit API code.

Features

  • Pure node:https output (no deps)
  • Handles headers, body, auth
  • URL parsing with node:url
  • Basic error handling included
  • Runs offline once loaded, great for private curl to Node.js Converter

How to use curl to Node.js Converter

  1. Paste curl. Drop your curl command.
  2. Click Run. The tool generates a dependency-free Node snippet.
  3. Copy to your project. Save as .mjs or adapt for CommonJS.

Example (before/after)

curl

curl https://api.example.com/users -H "X-Key: abc"

Node.js

import https from "node:https";
import { URL } from "node:url";

const target = new URL("https://api.example.com/users");
const options = {
  hostname: target.hostname,
  port: target.port || (target.protocol === "https:" ? 443 : 80),
  path: target.pathname + target.search,
  method: "GET",
  headers: {
    "X-Key": "abc"
  },
};

const req = https.request(options, (res) => {
  const chunks = [];
  res.on("data", (c) => chunks.push(c));
  res.on("end", () => {
    const body = Buffer.concat(chunks).toString("utf-8");
    console.log(res.statusCode, body);
  });
});

req.on("error", (err) => console.error(err));
req.end();

Common errors

HTTP vs HTTPS

The generated snippet imports node:https.

Fix: Swap to node:http if the URL is plain HTTP.

Streaming bodies

Large binary bodies are inlined.

Fix: For large uploads, switch to fs.createReadStream().

FAQ

Which flags are supported?

-X / --request, -H / --header, -d / --data*, -u / --user, --url.

Does it use any dependencies?

No — it relies only on node:https and node:url.

Does it auto-detect HTTP vs HTTPS?

It defaults to https; swap imports manually for http URLs.

Does it execute the request?

No — it only generates code.

Is input uploaded?

No — parsing runs in your browser.