Monitor an Express or NestJS API with one middleware
Install midline-agent, initialise it with a project key and add one line to your app. You get request logs, grouped errors and your server’s console output in the dashboard, without adding a hop to the request path.
Install
One package covers the server and the browser: midline-agent for the API, and midline-agent/browser for the web app. Create a project key under Project, then API Keys in the dashboard.
- npm install midline-agent
Express
Register the middleware before your routes so every request is seen, and the error handler after them. The error handler records the error and passes it on untouched, so your own handling is not changed.
NestJS
Nest handles exceptions in its own filters, so they rarely reach Express error middleware. The request middleware still records every 4xx and 5xx response, and Midline groups the 5xx responses into issues by method, route and status. Call MidlineAgent.shutdown() from your shutdown hook to flush what is queued.
Plain Node http
Not on a framework? midlineMiddleware() returns a plain (req, res, next) function you can call from a raw http server.
More than a request logger
A console logger such as morgan writes a line per request to a stream. Midline stores each request as a searchable event, calculates error rate and latency, captures what your server prints to the console, and groups failures into issues.
- Console output is captured with a severity taken from the line: ERROR and FATAL are high, WARN and other stderr output are medium.
- Printed lines never count towards request totals, error rate or latency.
- Credentials are masked in your process before anything is queued.
import { NestFactory } from "@nestjs/core";
import { MidlineAgent, midlineMiddleware } from "midline-agent";
import { AppModule } from "./app.module";
async function bootstrap() {
MidlineAgent.init({
apiKey: process.env.MIDLINE_API_KEY,
serviceName: "nest-api",
environment: process.env.NODE_ENV,
});
const app = await NestFactory.create(AppModule);
app.use(midlineMiddleware());
app.enableShutdownHooks();
await app.listen(3000);
}
bootstrap();
Questions
How do I monitor an Express API?
Install midline-agent, call MidlineAgent.init with your project key, register midlineMiddleware() before your routes and midlineErrorHandler() after them. Requests and errors then appear in the Midline dashboard.
Does it work with NestJS?
Yes. Register midlineMiddleware() with app.use. It records every 4xx and 5xx response, and 5xx responses are grouped into issues even though Nest handles exceptions in its own filters.
What happens if Midline is unreachable?
Your API is unaffected. Events wait in a bounded buffer and are retried with exponential backoff and jitter, honouring Retry-After. If the API key is rejected, the agent logs once and stops.
Is certificate verification ever disabled?
No. TLS verification is always on and there is no option to turn it off. A self-hosted Midline server behind a private CA can be trusted for the Midline connection only.
Node.js agent · API keys · Quick start
Start free