← All IntegrationsIntegration

Analytics for Express

Express is the most widely used Node.js web framework. BetterMeter's expressMiddleware() drops into your middleware chain and automatically tracks every API request — response times, status codes, error rates — all visible alongside your website analytics in the same dashboard.

One-line setup

server.ts — Express middleware integration
import express from "express";
import { BetterMeter } from "@bettermeter/node";

const app = express();
const bm = new BetterMeter({
  siteId: "my-api",
  apiKey: "bm_live_abc123",
});

// Add BetterMeter middleware — tracks all routes automatically
app.use(bm.expressMiddleware());

app.get("/api/users", (req, res) => {
  res.json({ users: [] });
});

app.post("/api/orders", (req, res) => {
  res.status(201).json({ id: "ord_123" });
});

app.listen(3000);

What gets tracked automatically

  • 01 Route and method — GET /api/users, POST /api/orders — grouped by Express route pattern, not raw URL.
  • 02 Status codes — 200, 201, 400, 404, 500 — see error rates per endpoint at a glance.
  • 03 Response time — p50, p95, p99 latency per route. Spot slow endpoints before users complain.
  • 04 Request volume — Requests per minute/hour/day per endpoint. Detect traffic patterns and anomalies.
  • 05 User agent classification — Which API clients are calling you — SDKs, bots, browsers, AI agents.

Custom tracking

The expressMiddleware() takes no arguments — it automatically tracks all routes. For custom behavior (excluding routes, adding properties, or grouping), use bm.trackApi() manually in individual route handlers instead.

Auto Route Grouping
/users/:id not /users/123
Latency Percentiles
p50, p95, p99
Error Rate Tracking
4xx and 5xx per route
Unified Dashboard
Web + API in one place
Zero Config
One middleware line
Non-Blocking
Async event dispatch