cURL to Code
Paste a curl command and get JavaScript fetch, TypeScript, Python requests, or Go net/http code with headers and body intact.
Runs entirely in your browser — nothing you paste is uploaded.
- Content-Type: application/json
- Accept: application/json
const options = {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify({
"customer_id": "cus_1042",
"items": [
{
"sku": "SOFT-01",
"qty": 2
}
],
"currency": "USD"
}),
};
const response = await fetch("https://api.example.com/v1/orders", options);
if (!response.ok) {
throw new Error(`Request failed: ${response.status} ${response.statusText}`);
}
const data = await response.json();
console.log(data);Flags that have no equivalent in the target language — output files, proxies, retries — are reported on the left instead of being dropped silently.
curl flag cheat sheet
quick reference- -X POST
- Sets the method; curl already sends POST as soon as a -d body is present, so -X is only needed for PUT, PATCH, or DELETE.
- -H 'Content-Type: application/json'
- Repeat -H for each header. Without a Content-Type, servers treat a JSON body as form data or plain text.
- -d '{"a":1}' / --data-raw
- -d strips newlines and encodes the body; --data-raw sends it untouched, which is what you want for JSON.
- -u user:pass
- HTTP Basic auth. The pair is base64-encoded into an Authorization header, which is only safe over HTTPS.
- -A / -b
- -A sets User-Agent and -b sends a Cookie header; both appear in the generated code as ordinary headers.
- -L -sS -o out.json
- Location-follow, silent but show errors, and write to a file — output and transport flags that do not exist in fetch code.
Related Node.js syntax guides
All Node.js guidesNode.js EventEmitter: once, error Events, and Listener Memory Leaks
emit is synchronous, so a throwing listener aborts the rest. An error event with no listener crashes the process, and a listener per request is the classic leak.
Node.jsNode.js fs/promises: Read, Write, Watch, and Atomic File Operations
writeFile truncates before writing, so a crash leaves half a file. The atomic pattern is temp file, fsync, rename; readFile loads everything, so large files need streams.
Node.jsNode.js Streams: Readable, Writable, Transform, and pipeline
pipe() forwards data but not errors; pipeline() destroys the chain and rejects. Backpressure is the false return from write(), and _flush that never calls back hangs forever.
Node.jsNode.js crypto: Hashing, HMAC, AES-GCM, and Random Bytes
Hashing, HMAC, AES-256-GCM and randomness solve different problems. Never reuse a GCM nonce, never hash a password with sha256, and compare secrets with timingSafeEqual.