---
title: "Express"
description: "Attach Blyp to Express middleware, use req.blypLog, and capture thrown errors with createExpressErrorLogger()."
canonical_url: "https://www.blyp.dev/docs/integrations/express"
markdown_url: "https://www.blyp.dev/docs/integrations/express.md"
last_updated: "2018-10-20"
x_farming_labs_generated_preamble: true
---

# Express
URL: /docs/integrations/express
LLM index: /llms.txt
Description: Attach Blyp to Express middleware, use req.blypLog, and capture thrown errors with createExpressErrorLogger().

# Express

Import from `@blyp/core/express`.

```ts
import express from "express";
import {
  createLogger,
  createExpressErrorLogger,
} from "@blyp/core/express";

const app = express();

app.use(createLogger({
  level: "info",
  clientLogging: true,
}));

app.get("/hello", (req, res) => {
  req.blypLog.info("express-route");
  res.status(200).send("ok");
});

app.use(createExpressErrorLogger());
app.use((error, _req, res, _next) => {
  res.status(500).json({ message: error.message });
});
```

## Why the extra error middleware matters

`createExpressErrorLogger()` stores the thrown error on `res.locals` so Blyp can emit an `http_error` record when the response finishes.

## What auto-logged requests look like

With automatic request logging enabled, Blyp emits terminal output like:

```text
[INFO]  GET  /health        200  2ms
[INFO]  POST /checkout      200  143ms
[INFO]  GET  /users/42      404  8ms
[ERROR] POST /payments      500  1203ms
```

Fields included automatically: method, path, status code, and duration.

**In production (NDJSON):**

```json
{"level":"info","time":1710000000000,"msg":"GET /health","type":"http_request","method":"GET","url":"/health","statusCode":200,"responseTime":2}
{"level":"info","time":1710000000001,"msg":"POST /checkout","type":"http_request","method":"POST","url":"/checkout","statusCode":200,"responseTime":143}
```

## Relevant types

```ts
import type {
  ExpressLoggerConfig,
  ExpressLoggerMiddleware,
  ExpressErrorLoggerMiddleware,
} from "@blyp/core/express";
```

## Sitemap

See the full [sitemap](/sitemap.md) for all pages.
Docs-scoped sitemap: [/docs/sitemap.md](/docs/sitemap.md).
Well-known sitemap: [/.well-known/sitemap.md](/.well-known/sitemap.md).
