---
title: "NestJS"
description: "Initialize Blyp before Nest bootstrap, wire BlypModule.forRoot(), and use req.blypLog inside controllers."
canonical_url: "https://www.blyp.dev/docs/integrations/nestjs"
markdown_url: "https://www.blyp.dev/docs/integrations/nestjs.md"
last_updated: "2018-10-20"
x_farming_labs_generated_preamble: true
---

# NestJS
URL: /docs/integrations/nestjs
LLM index: /llms.txt
Description: Initialize Blyp before Nest bootstrap, wire BlypModule.forRoot(), and use req.blypLog inside controllers.

# NestJS

Import from `@blyp/core/nestjs`.

## Required bootstrap order

Call `createLogger()` before `NestFactory.create(...)`.

```ts
import "reflect-metadata";
import { Module, Controller, Get, Req } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { logger } from "@blyp/core";
import { createLogger, BlypModule } from "@blyp/core/nestjs";

@Controller()
class AppController {
  @Get("/hello")
  hello(@Req() request: { blypLog?: { info(message: string): void } }) {
    request.blypLog?.info("nest-request");
    logger.info("nest-route");
    return { ok: true };
  }
}

@Module({
  imports: [BlypModule.forRoot()],
  controllers: [AppController],
})
class AppModule {}

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

const app = await NestFactory.create(AppModule);
await app.listen(3000);
```

## What BlypModule does

- applies middleware to all routes
- registers a global interceptor
- registers a global exception filter
- supports both Nest Express and Nest Fastify adapters

If you call `BlypModule.forRoot()` before `createLogger(...)`, Blyp throws an initialization error during bootstrap.

## 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 {
  NestLoggerConfig,
  NestLoggerContext,
  NestAdapterType,
} from "@blyp/core/nestjs";
```

## 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).
