Skip to content
Docs menu
Integration · Express

Express

Two middlewares and you're done. requestHandler() opens an async-context frame for each request so captured errors include method, url, request ID, and the current user. errorHandler() catches everything that reaches Express's error chain. Works with Express 4 and 5 on Node ≥ 20.

AI-assisted setup

Paste the prompt below into Claude Code, Cursor, Copilot, or Codex — your agent will detect your package manager, install both packages, create the observability module, and register the middlewares in the correct order.

AI agent prompt · Express
You are adding the @nreactive/core + @nreactive/express SDKs to this Express project. nreactive is a production error-monitoring service that opens AI-generated pull requests to fix the errors it catches.

Do the following with the project's existing package manager (detect it from the lockfile: package-lock.json → npm, pnpm-lock.yaml → pnpm, yarn.lock → yarn, bun.lockb → bun):

1. Install the packages @nreactive/core and @nreactive/express.
2. Create "src/observability/nreactive.ts" (or ".js" if the project is plain JavaScript) that imports init from @nreactive/core and calls it with { appId: process.env.NREACTIVE_APP_ID, environment: process.env.NODE_ENV, release: process.env.APP_VERSION }. Export nothing — the module is used for its import side effect.
3. In the server entry file, add import "./observability/nreactive"; as the VERY FIRST import — before any other import including "express".
4. In the Express app setup:
   - Call app.use(requestHandler()) from @nreactive/express BEFORE any routes.
   - Call app.use(errorHandler()) from @nreactive/express AFTER all routes and after any other error middleware.
5. Add NREACTIVE_APP_ID= to .env.example (create it if missing) and document it in the README's environment-variables section. The user obtains their App ID from https://nreactive.com/dashboard/apps.
6. Restart the server and throw a test error from a route (e.g. app.get("/boom", () => { throw new Error("nreactive test"); })) to confirm events appear in the dashboard.

Do not invent additional configuration. Stop and ask if the project structure doesn't match these assumptions (for example, if the project is not using Express).

Manual setup

1

Get your App ID

Sign in and grab your App ID from the Apps page. It looks like app_ab12cd34ef. Export it as NREACTIVE_APP_ID so the SDK can read it from process.env.

2

Install

pnpm add @nreactive/core @nreactive/express

Or npm install @nreactive/core @nreactive/express / yarn add … / bun add ….

3

Wire it up

Create src/observability/nreactive.ts:

import { init } from "@nreactive/core";
 
init({
  appId: process.env.NREACTIVE_APP_ID!,
  environment: process.env.NODE_ENV,
  release: process.env.APP_VERSION,
});

Then in your server entry file, import the observability module first and register the two middlewares around your routes:

import "./observability/nreactive";
 
import express from "express";
import { requestHandler, errorHandler } from "@nreactive/express";
 
const app = express();
 
app.use(requestHandler());        // FIRST — wraps each request in async context
app.use(express.json());
 
app.get("/", (req, res) => {
  res.send("hello");
});
 
app.use(errorHandler());          // LAST — captures thrown + next(err) errors
 
app.listen(3000);

If your auth middleware attaches req.user = { id, email, username }, the request handler picks it up automatically and tags every error with that user.

4

Verify

Restart the server and hit a route that throws:

app.get("/boom", () => {
  throw new Error("nreactive test");
});
curl http://localhost:3000/boom

Within a few seconds the event shows up on the Errors page of your dashboard with method, URL, request ID, and user attached.

Next steps