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.fetchandAbortSignal.any). - The
tlsoption triggers a lazyawait import('undici')to create a custom dispatcher. This is the only time parcely imports a Node-specific module. tls.rejectUnauthorized: falseemits a one-shotconsole.warnto remind you not to use it in production.- Node
fs.ReadStreambodies are transparently converted to WebReadableStream.