CControxity Docs
GuidesReferenceHTTP APIOpen Controxity
Platforms

Node.js

Express, Fastify, NestJS or plain Node. About five minutes, and nothing changes for your users.

1. Install#

The SDK is one file, kept with your code (it isn't on npm yet). In your server's folder, with your Controxity's address:

curl -fsSL https://controxity.example.com/sdk/node.js -o controxity.js
curl -fsSL https://controxity.example.com/sdk/node.d.ts -o controxity.d.ts   # TypeScript only

Its first line says its version (// controxity-sdk 0.25.6 (Node.js)): fetch it again the same way to update it. Then require("./controxity") (or import controxity from "./controxity.js") where the examples below say "controxity".

Get a key under Where it runs → Add a place and keep it in CONTROXITY_KEY (see Your first error).

2. Start it, as early as you can#

Before your other imports, so it sees errors from the start.

const controxity = require("controxity");   // or: import controxity from "controxity"

controxity.init({
  key: process.env.CONTROXITY_KEY,
  url: process.env.CONTROXITY_URL,
  version: "1.4.2",          // or the git commit it runs: "3f9c2a1"
});

3. Connect your framework#

Don't skip this. Frameworks catch your routes' errors and answer with a 500 themselves, so Controxity never sees them without this one line. Your error pages don't change.
app.use(controxity.express());   // after your routes

Already have your own catch-all error handler or filter? Then the framework line may never run: add controxity.captureError(error, { input }) where your handler deals with a 500, with the request's params, query and body as input (only their shape is sent). Each request keeps its own steps by itself; to start them with the route, call controxity.step("route:POST /carts/:id") first, with the request's method and its route's pattern (never the path asked for, which can hold an id). A 4xx is the visitor's mistake, so it isn't reported.

4. Check it works#

console.log(await controxity.check());   // { ok: true, why: "Connected to controxity.example.com" }

It says what's wrong if the key is refused or Controxity can't be reached. Then make one route throw: it's on Problems within a minute.

5. Ship safely (optional)#

// What must always be true. A broken one is a problem, but nothing is thrown:
controxity.expect("total-not-negative", total >= 0, { input: { cart } });

// New or risky code, off until a person turns it on (for everyone or a share), and off again by itself if it hurts:
if (controxity.flag("new-checkout", { id: user.id })) return newCheckout(cart);

// A step worth seeing before an error (routes, fetch calls and events are noted by themselves):
controxity.step("cart.loaded");

Expectations · Switches · Steps before an error. In CI, one more step tells Controxity what each release is and sends its source maps: Releases from CI.

TypeScript#

To see your .ts files, not the compiled ones: set "sourceMap": true in tsconfig.json and start with node --enable-source-maps dist/main.js. The flag matters, because your imports load before init() runs.

Also useful#

controxity.captureError(error, { where: "orders" });      // an error you caught yourself
controxity.health("database", false, "high");             // something is down; health("database", true) clears it
controxity.event("payment_failed");                       // counted
controxity.shape({ items: undefined });                    // what captureError sends for input: { items: "undefined" }
await controxity.report({ title: "Booking failed", what }); // what a person told you
await controxity.shutdown();                              // sends what's waiting, when the app stops

Every function, with what it sends: Node SDK reference.

Is it up?#

Once a minute, when there's nothing else to send, it sends a heartbeat. If they stop for 3 minutes, Controxity marks this server Down, tells the people on the product, and tells them again when it's back. shutdown() says it's stopping on purpose, so a planned stop isn't counted as an outage.

A crash that ends the process is saved to a small file in the system's temp folder and sent when your app starts again.

If nothing shows up#

Turning things off#

Option of init()Off means
captureInput: falseNo input shapes
breadcrumbs: falseNo steps, and fetch is left as it was
captureUncaught: falseUncaught exceptions aren't reported
heartbeat: falseNo heartbeat (not a server)
Controxity 1.132.0These pages are in the repository: docs/site