SDK guides

Backend errors on Node

@fixback/node is the backend error SDK. Capture unhandled crashes and manual captures from a Node server and file them into the same Fixback pipeline your frontend uses — one queue for your whole product.

Backend errors authenticate with a secret key, so they arrive Internal tier and tagged platform: node. Fleet-wide crash-loops collapse into a single Issue with a rising occurrence count instead of flooding your queue.

Every secret key belongs to one of the Project's environments, and a backend error lands in the environment of the key that sent it — so there is no environment option. Give each server its own environment's key: Staging's on the staging server, Production's in production.

Install

shell
npm install @fixback/node

The Express and NestJS adapters are optional — install the framework you use.

Quick start

Call init as early as possible in your process — before your app boots — so the process handlers are installed before anything can throw:

instrument.ts
// instrument.ts — imported first in your entry fileimport { init } from "@fixback/node";init({  secretKey: process.env.FIXBACK_SECRET_KEY!, // sk_… (never your publishable key)  release: process.env.GIT_SHA,               // symbolicated against your uploaded sourcemaps  enabled: process.env.NODE_ENV === "production", // gate auto-capture off in local dev});

That single call wires:

  • a batched secret-key transport that keeps an error until Fixback has filed it — retrying, honouring Retry-After, and flushing on shutdown (see Delivery);
  • process-level uncaughtException / unhandledRejection capture that leaves your process to do what Node would (see Crashes and unhandled rejections);
  • and the manual capture API below.

Two options fall back to environment variables when you don't pass them: release to FIXBACK_RELEASE, and apiUrl to FIXBACK_API_URL (the hosted API, https://api.fixback.dev, when neither is set). An explicit option wins. Use the release your sourcemaps were uploaded under, and frames map back to your source from CommonJS or ES-module builds, on POSIX or Windows.

Crashes and unhandled rejections

Listening for uncaughtException or unhandledRejection switches off what Node itself does with one, so the SDK does it instead, after capturing (handled: false):

  • An uncaught exception is flushed, printed, and exits the process with code 1, as Node would.
  • An unhandled rejection follows your --unhandled-rejections mode, read from NODE_OPTIONS and the command line. In Node's default throw mode the capture is flushed (within a short timeout) and the rejection is raised as an uncaught exception: the process prints it and exits 1, or your own uncaughtException handler receives it. warn-with-error-code prints Node's warning and sets exit code 1; warn and none change nothing.

When your app has its own listener for the event, the SDK only captures and your listener decides what happens.

Delivery

Errors buffer in memory and go to Fixback in batches — when 100 are buffered, every 5 seconds, on flush(), and on close(). An error leaves the buffer only once Fixback has filed it:

  • Retried. A batch that fails — a 5xx, a timeout, Fixback unreachable — is kept and sent again after 10 seconds, then 20, 40, … up to 5 minutes between tries. An error is given up after 6 failed sends, about five minutes of an unreachable Fixback.
  • Rate limits honoured. When your environment's error budget is spent, Fixback files what it can and answers the rest rate_limited, or the whole batch 429, with a Retry-After. The SDK sends nothing until that wait is over, then sends those errors again; each wait counts as one of the 6 tries.
  • Nothing lost to a pause. Errors captured while the SDK waits keep buffering, and a repeat of one already buffered folds into it — so occurrence counts still add up. The buffer holds maxQueueSize distinct errors (1024): past that the oldest is dropped.
  • Never resent when it can't pass. An error Fixback could not read, or a batch refused outright (a 4xx other than 429), is dropped rather than retried.
  • Flushed on shutdown. When your process's event loop runs dry (beforeExit), what was captured since the last flush is sent. On SIGTERM or SIGINT, if your app has no handler of its own for the signal, the SDK sends what is buffered (waiting at most 2 seconds), then re-raises the signal — so the process still ends exactly as it would have.

A secret key Fixback refuses (401: revoked, its environment deleted, or a publishable key) or a suspended workspace (403) is said once on standard error, so a misconfigured deploy is never silent. debug: true says more: why the SDK is inert, what every send answered, and what is retried or given up.

Manual capture

Report a handled error or a message from anywhere in your process:

ts
import { captureException, captureMessage } from "@fixback/node";try {  await risky();} catch (err) {  captureException(err);           // handled: true}captureMessage("cache miss storm", "warning");

Chained errors

A captured error brings the errors behind it: its cause, followed five deep, and an AggregateError's errors, ten of one aggregate — at most ten in all, each with its own name, message and stack frames, scrubbed like the error itself. The Issue shows them as Caused by sections under the error, and the Brief and the hand-off to your coding agent include them. The outer error leads, and the types behind it join its fingerprint; beforeSend sees the chain as event.errorCauses.

Grouping

Repeats of one error fold into one Issue with a rising count, across every instance and deploy. An error's fingerprint is its type with the types behind it, and your own top frames — never node_modules or node: internals — by function and file, never by line. An anonymous callback is known by the named function it is written in. The message counts only when the frames can't name where the error was thrown, with every number collapsed: User 42 not found and User 43 not found from one throw site are one Issue.

Group your own way with fingerprint, on a capture or in beforeSend. event.errorSignature is the fingerprint the SDK computed, and fingerprint wins over it:

ts
import { captureException, captureMessage, init } from "@fixback/node";// "{{ default }}" is the fingerprint the SDK computed: split it by tenantcaptureException(err, { fingerprint: ["{{ default }}", tenantId] });captureMessage("Payment provider down", "error", { fingerprint: ["payment-provider-down"] });init({  secretKey: process.env.FIXBACK_SECRET_KEY,  beforeSend(event) {    if (event.type === "AbortError") event.fingerprint = ["aborted-request"];    return event;  },});

Fingerprints changed in version 2 of these rules. An Issue filed before you upgrade keeps folding: the SDK also sends the old key, and Fixback moves the Issue onto the new one the first time it sees both.

Confirming the connection

The browser and Expo SDKs announce themselves the moment they load, so a Project with either installed flips to Connected on the next page view. A server has no equivalent moment — @fixback/node sends nothing until it captures something — so the first capture is what confirms the install. Trigger one deliberately:

ts
import { captureException } from "@fixback/node";captureException(new Error("Fixback test"));

The Project's status flips as soon as that batch lands, and the error arrives in the queue as an Internal-tier Issue you can resolve straight away. If nothing shows up, check that enabled is not gating capture off in this environment and that the secret key has not been revoked.

Express

ts
import express from "express";import { fixbackRequestContext, fixbackErrorHandler } from "@fixback/node/express";const app = express();app.use(fixbackRequestContext()); // opens per-request context (before your routes)// … your routes …app.use(fixbackErrorHandler());   // captures errors that reach next(err) (after your routes)

A route in a mounted router is recorded by its full pattern: a router at app.use("/orgs/:org", posts) with posts.get("/posts/:postId") records /orgs/:org/posts/:postId, from the error handler and from a captureException inside the route alike, on Express 4 and 5. If a mount's pattern can't be worked out for certain, the route is left out instead. That happens with a parameter that shares its segment with text (/report-:year), a wildcard, a RegExp mount, or an error from a mounted sub-app that reaches the parent app's error handler.

NestJS

ts
import { Module } from "@nestjs/common";import { FixbackModule } from "@fixback/node/nestjs";@Module({ imports: [FixbackModule.forRoot()] })export class AppModule {}

FixbackModule.forRoot() registers the request-context middleware and a global exception filter. The filter captures what a request throws, then lets Nest's own exception filter produce the response, so your error handling is unchanged. An exception from a microservice (RPC) or GraphQL call is captured too, then left to Nest's default handling for that context. Global filters don't reach WebSocket gateways. A gateway that applies the filter with @UseFilters(FixbackExceptionFilter) has its exceptions captured, and the client still gets Nest's usual exception event.

Client errors aren't filed by default

Both adapters file what the server got wrong: a 5xx, or an error with no HTTP status. A request answered with a 4xx is not filed, whether that's a bot probing /.env and getting a 404, an expired session's 401, or a ValidationPipe's 400. Your own error handling still runs exactly as before. To file some of them, list them in captureClientErrors ([403, 409], say, to catch a broken guard). Pass true to file every 4xx. A captureException you call yourself is always filed.

Attaching a user and tags

The SDK never scrapes user identity. Attach an app-supplied reference and it rides along with the errors captured in its scope, and shows on the Issue:

ts
import { setTag, setUser } from "@fixback/node";setUser(currentUser.id); // an opaque ref you choose — not a name/email unless you send onesetTag("tenant", currentTenant.slug); // a key/value pair, shown on the Issue as a chip

Inside a request, both belong to that request. Outside one — a queue consumer, a cron job, startup — they set process-wide values that every error carries, and that a request without its own value carries too. setUser(null) clears the user; setTag(key, null) removes a tag. A tag key is up to 32 letters, digits, _, ., : or -; a value up to 200 characters on one line; an error carries at most 50.

An error carries the lead-up of its own request, and the Issue's Trace tab lists it in order above the failing request: every console call's level and message (cut to 300 characters), and every outgoing request through http/https or fetch — its method, its URL without the query string, its status, how long it took and how it ended. Never a header or a body, and never the SDK's own batches.

Each request records its own, so an error never carries another request's breadcrumbs; work outside a request records into one process-wide set, which only an error outside a request carries. An error carries the newest maxBreadcrumbs (50 by default) from the last five minutes. Requests are read from Node's diagnostics_channel, so nothing is patched, and the default scrub sweeps every breadcrumb's URL and message.

ts
init({  secretKey: process.env.FIXBACK_SECRET_KEY!,  maxBreadcrumbs: 30,  capture: { console: true, network: true }, // turn either off with false  // See each breadcrumb as it is recorded: edit it, or drop it with null.  beforeBreadcrumb: (crumb) => (crumb.url?.includes("/health") ? null : crumb),});

Where it ran

Every batch says which process sent it: the SDK's name and version (the Issue's SDK row), your serviceName (or FIXBACK_SERVICE_NAME), and the host name, Node.js version and OS, read once at init. So several services, or several instances of one, filing into one environment can be told apart on the Issue. A captureMessage level shows there too.

Privacy & fail-quiet

Private by default: the SDK captures the route pattern (never the concrete path with values: a route whose pattern it can't work out is left out), method, status, a correlation id, the app-supplied user ref and tags, where the process runs (service, host, Node.js version, OS), and the request's scrubbed breadcrumbs — never auth/cookie headers, env vars, or query values, and no request/response bodies unless you opt in with captureBodies — useful for debugging on staging. A beforeSend(event) hook redacts further or drops an event (return null). See Privacy & data.

And it fails quiet: if Fixback is unreachable or misconfigured, your server keeps running normally — observability never becomes an outage.