API reference

@fixback/node reference

The complete API of @fixback/node. For a narrative walkthrough, see the Backend errors guide.

Exports

ts
import {  init,  captureException,  captureMessage,  setUser,  mintHostIdentity,} from "@fixback/node";// framework adapters (optional, subpath imports):import { fixbackRequestContext, fixbackErrorHandler } from "@fixback/node/express";import { FixbackModule } from "@fixback/node/nestjs";

init(options)

Call once, as early in the process as possible.

OptionTypeDescription
secretKeystringRequired. The Project's secret key (sk_…). Server-side only.
environmentstringThe deploy environment — "production", "staging", … Stored on every captured error.
releasestringThe build identifier, symbolicated against sourcemaps uploaded for the same release.
enabledbooleanGate capture on or off — e.g. process.env.NODE_ENV === "production" to stay quiet in local dev.
beforeSend(event) => event | nullRedact fields, or drop an event entirely by returning null.
scrubbooleanRun the built-in PII scrubbers before beforeSend. Defaults to true.
apiUrlstringThe Fixback API origin. Override for a self-hosted deployment.
autoCapturebooleanThe umbrella for the two process handlers below. Defaults to true; false installs neither.
captureUncaughtExceptionbooleanInstall the polite uncaughtException handler. Defaults to autoCapture.
captureUnhandledRejectionbooleanInstall the polite unhandledRejection handler. Defaults to autoCapture.
requestIdHeaderstringThe header a correlation id is read from. Defaults to x-request-id.

Set the two per-signal flags to override the umbrella individually — e.g. { autoCapture: false, captureUnhandledRejection: true } installs only the rejection handler.

Transport tuning

Sensible by default; reach for these only when your traffic shape asks for it.

OptionDefaultDescription
maxBatchSize100Flush once the buffer reaches this many errors. Capped at the server's limit of 500.
flushIntervalMs5000Flush a non-empty buffer at least this often.
maxQueueSize1024Cap the in-memory buffer so a flood can't grow it without bound.
timeoutMs30000Per-request transport timeout; 0 disables it.

The single init call also wires a batched secret-key transport (backs off on 429, honouring Retry-After) and process-level uncaughtException / unhandledRejection capture that never changes your process's exit behaviour.

Capture functions

FunctionDescription
captureException(err)Report a handled error (handled: true).
captureMessage(message, level?)Report a message string with a level (e.g. "warning").
setUser(ref)Attach an app-supplied, opaque user reference to errors captured during the current request.

mintHostIdentity(options)

A Host identity is the escape hatch for a product that already knows who its users are: your server mints a short-lived token from the Project's secret key and hands it to a capture SDK (web or Expo) as its hostIdentity. Fixback verifies it and tiers the Reporter — Internal when the token's email is an Org Member, otherwise Invited — with no Connect round trip. A verified Host identity whose email matches a Fixback Account resolves to that same person, so the host and the platform are one Reporter.

ts
import { mintHostIdentity } from "@fixback/node";// On your server, for a user you already authenticated:const hostIdentity = mintHostIdentity({  secretKey: process.env.FIXBACK_SECRET_KEY!, // sk_… — never ship it to a client  subject: user.id,                            // your stable id for the user (JWT sub)  email: user.email,                           // optional — Member ⇒ internal tier  expiresInSeconds: 3600,                       // optional — defaults to one hour});// Hand it to a capture SDK as its hostIdentity option://   web:  Fixback.init({ key: "pk_…", hostIdentity })//   expo: <FixbackProvider options={{ key, origin, hostIdentity }} />
OptionTypeDescription
secretKeystringRequired. The Project's secret key (sk_…), issued in the dashboard. Signs the token; keep it server-side.
subjectstringRequired. Your stable identifier for the user — the JWT sub, which keys the Reporter.
emailstringThe user's email. Decides internal vs invited, and unifies the Reporter with a matching Account. Omit for a valid-but-external identity (invited).
expiresInSecondsnumberToken lifetime; defaults to one hour. An exp is always set — an identity assertion must expire.

The recipe is an HS256 JWT signed with sha256(secretKey) — the value Fixback stores for the key and verifies against (the secret plaintext is shown once at issuance and never kept). This helper is that recipe, so you never hand-roll JWT signing. Issue and revoke secret keys under a Project's Secret keys in the dashboard; a revoked key stops verifying at once.

Express adapter — @fixback/node/express

MiddlewareWhereDescription
fixbackRequestContext()before your routesOpens per-request context so captures carry request metadata.
fixbackErrorHandler()after your routesCaptures errors that reach next(err).

NestJS adapter — @fixback/node/nestjs

ExportDescription
FixbackModule.forRoot()Registers the request-context middleware and a global exception filter that captures thrown request errors and re-throws them, leaving your own error handling unchanged.