Skip to main content
The official Peeng JavaScript and TypeScript SDK (npm install peeng) gives you a fully-typed client that wraps POST /v1/logs with non-blocking queuing, automatic batching, retries, and idempotency. Every peeng.info(...) call enqueues the log and returns immediately — the SDK handles delivery entirely in the background, so logging never blocks your app or throws exceptions into it.
MIT licensed. Requires Node ≥ 18 (uses the built-in global fetch and crypto.randomUUID); also works in browsers and edge runtimes.

Install

Quick start

Use ESM imports in TypeScript or modern Node.js:
CommonJS works the same way — swap import for require:

Why use the SDK

Background batching

peeng.info(...) returns immediately — it enqueues, it never blocks on network I/O. The buffer flushes automatically every flushIntervalMs, or as soon as it hits maxBatchSize.

Automatic retries

Transient failures (network errors, 429s, 5xxs) are retried with backoff, reusing one Idempotency-Key per batch so retries can’t double-insert.

Never throws

Delivery failures go to onError instead of raising out of a logging call — a Peeng outage should never crash your app.

Fully typed

Ships CJS, ESM, and .d.ts declarations — full autocomplete on log options in every editor.

Constructor options

Pass an options object to new PeengClient(options) to configure the client.

Logging methods

The SDK exposes one convenience method per log level:
opts.statusCode is required on every call (100–599). The following fields are optional: service, metadata, stackTrace, hostname, requestId, userId, timestamp, and a per-call environment override. See the field reference for what each one means. For anything the convenience methods don’t cover, use the generic form:

Graceful shutdown

Call flush() to send whatever is currently in the buffer right now, and close() to stop the background timer and flush any remaining logs before your process exits.
Hook into your process’s SIGTERM signal to give the client time to drain before shutdown:
The client also best-effort auto-flushes on Node’s beforeExit event as a safety net — close() is the deterministic way to guarantee delivery.

Custom batching config

Override the default batching and retry settings at construction time:

Error handling

Background delivery failures are routed to onError, but you can also await peeng.flush() directly and catch errors in a try/catch block. The SDK surfaces two error types:
  • PeengApiError — the server responded with an error envelope. Carries statusCode, message, error (from the server envelope), and a context object with batchSize, idempotencyKey, and url. This is thrown for non-retryable errors (e.g. 400) or after retries are exhausted (e.g. repeated 5xx).
  • Plain Error — a network failure with no HTTP response at all (DNS failure, connection refused), surfaced after retries are exhausted.
See Errors for the full retryable/non-retryable rules.