Skip to main content
All recipes

Express

CodeMiddlewareNode.js

Mount the CheckUpstream middleware before your Express routes. It initializes the SDK once to measure outbound fetch calls; it does not attach incoming route or request context.

1. Install

Bash
npm install @checkupstream/sdk

2. Mount the middleware

server.ts
import express from "express";
import { checkUpstreamMiddleware } from "@checkupstream/sdk/integrations/express";

const sdkKey = process.env.CHECKUPSTREAM_SDK_KEY;
if (!sdkKey) throw new Error("Set CHECKUPSTREAM_SDK_KEY before starting the app");

const app = express();

app.use(
  checkUpstreamMiddleware({
    sdkKey,
    services: ["api.github.com", "api.stripe.com"],
  }),
);

app.get("/api/users", async (_req, res) => {
  // Outbound calls here are tracked automatically.
  const response = await fetch("https://api.github.com/zen");
  res.json({ message: await response.text() });
});

app.listen(3000);

Continue your setup

Check runtime availability and credentials before deploying an integration.