NestJS

Set up OneMinute Logs in NestJS.

Install the NestJS SDK, register its global module once, and inject the type-safe logging service into controllers, providers, or background workers.

If you are using Cursor, Claude Code, Codex, Antigravity, or any other AI IDE, follow our Setup with AI guide.

1. Install the SDK

Add the OneMinute Logs SDK for this framework.

npm install @oneminutelogs/nestjs

2. Create an API key

Create an API key from your OneMinute Logs dashboard and add it to your environment variables. Open the API key guide.

ONE_MINUTE_LOGS_API_KEY=your_oml_api_key

3. Create src/app.module.ts

Initialize the logger once and import it anywhere you need to send events.

import { Module } from "@nestjs/common";
import { OneMinuteLogsModule } from "@oneminutelogs/nestjs";

@Module({
  imports: [
    OneMinuteLogsModule.forRoot({
      apiKey: process.env.ONE_MINUTE_LOGS_API_KEY!,
      appName: "my-nest-api",
      environment: process.env.NODE_ENV || "development",
      autoLogRequests: true,
    }),
  ],
})
export class AppModule {}

OneMinuteLogsModule is global, so register it once in your root module and inject OneMinuteLogsService anywhere in the application.

Optional: log HTTP requests automatically

Register the interceptor after creating the Nest application to capture request duration, status, and metadata.

import { NestFactory } from "@nestjs/core";
import {
  OneMinuteLogsInterceptor,
  OneMinuteLogsService,
} from "@oneminutelogs/nestjs";
import { AppModule } from "./app.module";

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  const logs = app.get(OneMinuteLogsService);

  app.useGlobalInterceptors(new OneMinuteLogsInterceptor(logs));

  await app.listen(process.env.PORT ?? 3000);
}

void bootstrap();

4. Send events

Use event types like info, warning, error, audit, and metric to keep your production timeline useful and searchable.

import { Body, Controller, Post } from "@nestjs/common";
import { OneMinuteLogsService } from "@oneminutelogs/nestjs";

@Controller("checkout")
export class CheckoutController {
  constructor(private readonly logs: OneMinuteLogsService) {}

  @Post()
  async create(@Body() body: any) {
    await this.logs.info({
      message: "Checkout started",
      service: "checkout",
    });

    await this.logs.warning({
      message: "Inventory is running low",
      service: "inventory",
      importance: "medium",
    });

    await this.logs.audit({
      message: "Checkout request accepted",
      service: "checkout",
      security: {
        auth_status: "success",
      },
      track: {
        user_id: body.userId,
      },
    });

    await this.logs.metric({
      message: "Checkout amount recorded",
      service: "checkout",
      metrics: {
        custom: {
          amount: body.amount,
        },
      },
    });

    try {
      return { ok: true };
    } catch (error) {
      await this.logs.error({
        message: "Checkout failed",
        service: "checkout",
        operation: "create",
        importance: "critical",
      });

      throw error;
    }
  }
}

What's next?

After events are flowing, alerts, webhooks, live dashboards, and search all work from the same event pipeline.

Found something unexpected? Let us know.