Skip to main content

Node.js usage

Use case

Use parcely in a Node.js 20+ application.

Smallest working example

import { createClient } from '@parcely/core'

const http = createClient({
baseURL: 'https://api.example.com',
timeout: 5000,
})

const { data } = await http.get('/users')
console.log(data)

No special configuration needed. parcely uses globalThis.fetch, which is available in Node 20+.

TLS overrides

For self-signed certificates or custom CA bundles, use the tls option:

const http = createClient({
baseURL: 'https://internal.example.com',
tls: {
rejectUnauthorized: false, // accept self-signed certs (dev only!)
},
})

See the TLS: self-signed certs and TLS: custom CA guides for details.

File uploads from disk

import { createReadStream } from 'node:fs'

await http.post('/upload', createReadStream('./data.csv'), {
headers: { 'Content-Type': 'text/csv' },
})

Axios equivalent

// axios in Node:
import axios from 'axios'
const http = axios.create({ baseURL: 'https://api.example.com' })
const { data } = await http.get('/users')

// parcely (identical pattern):
import { createClient } from '@parcely/core'
const http2 = createClient({ baseURL: 'https://api.example.com' })
const { data: d2 } = await http2.get('/users')

Notes and gotchas

  • Requires Node 20 or later (for globalThis.fetch and AbortSignal.any).
  • The tls option triggers a lazy await import('undici') to create a custom dispatcher. This is the only time parcely imports a Node-specific module.
  • tls.rejectUnauthorized: false emits a one-shot console.warn to remind you not to use it in production.
  • Node fs.ReadStream bodies are transparently converted to Web ReadableStream.