npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@fullstackhouse/nestjs-logger-middleware

v1.1.0

Published

A configurable HTTP logger middleware for NestJS applications

Downloads

5

Readme

NestJS Logger Middleware

Configurable HTTP request/response logger middleware for NestJS applications.

Installation

npm install @fullstackhouse/nestjs-logger-middleware

Usage

Basic Usage (Module)

Import and configure the module in your AppModule:

import { Module } from "@nestjs/common";
import { LoggerMiddlewareModule } from "@fullstackhouse/nestjs-logger-middleware";

@Module({
  imports: [LoggerMiddlewareModule.forRoot()],
})
export class AppModule {}

With Configuration

import { Module } from "@nestjs/common";
import { LoggerMiddlewareModule } from "@fullstackhouse/nestjs-logger-middleware";

@Module({
  imports: [
    LoggerMiddlewareModule.forRoot({
      routes: "*", // default, can be string or array of strings
      skipPaths: ["/health", /^\/metrics/],
      logHeaders: ["x-user-id", "x-tenant-id"],
      logClientIp: true,
      logUserAgent: true,
      logContext: (req) => ({ userId: req.headers["x-user-id"] }),
    }),
  ],
})
export class AppModule {}

Manual Middleware Application

You can also apply the middleware manually:

import { Module, NestModule, MiddlewareConsumer } from "@nestjs/common";
import { LoggerMiddleware } from "@fullstackhouse/nestjs-logger-middleware";

@Module({})
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer.apply(LoggerMiddleware).forRoutes("*");
  }
}

Configuration Options

Module Options

| Option | Type | Default | Description | | ----------------- | --------------------------------------------------------------------- | ----------- | ----------------------------------------------------- | | routes | string \| string[] | '*' | Routes to apply the middleware to | | skipPaths | (string \| RegExp)[] | [] | Paths to skip logging (unless error occurs) | | logRequestBody | boolean | false | Include request body in logs | | logResponseBody | boolean | false | Include response body in logs | | logClientIp | boolean | false | Extract and log client IP from headers/request | | logUserAgent | boolean | false | Extract and log user agent | | logHeaders | string[] | [] | Additional headers to extract and log | | logTrace | boolean | true | Extract and log trace ID from headers or generate one | | logContext | (req, res?) => Record<string, unknown> | undefined | Function to extract custom context for logs | | skip | (req, res?) => boolean \| { request?: boolean; response?: boolean } | undefined | Dynamic skip function for request/response logs |

Logged Information

Request Logs

  • HTTP method
  • Request path
  • Client IP (if enabled)
  • User agent (if enabled)
  • Trace ID (from sentry-trace, x-trace-id, or auto-generated)
  • Custom headers (if configured)
  • Request body (if enabled)

Response Logs

  • HTTP method
  • Request path
  • Status code
  • Response time
  • Query parameters (if present)
  • Client IP (if enabled)
  • User agent (if enabled)
  • Trace ID
  • Custom headers (if configured)

Examples

Skip Health Checks in Production

LoggerMiddlewareModule.forRoot({
  skipPaths:
    process.env.NODE_ENV === "production" ? ["/health", "/metrics"] : [],
});

Extract User Context from Headers

LoggerMiddlewareModule.forRoot({
  logHeaders: ["x-user-id", "x-tenant-id", "x-organization-id"],
});

Debug Mode with Request Bodies

LoggerMiddlewareModule.forRoot({
  logRequestBody: process.env.NODE_ENV !== "production",
});

Dynamic Logging Context

LoggerMiddlewareModule.forRoot({
  logContext: (req, res) => {
    const trace = req.headers["sentry-trace"]?.split("-")[0];
    return {
      trace,
      userId: req.headers["x-user-id"],
      tenant: req.headers["x-tenant-id"],
    };
  },
});

Dynamic Skip Logic

LoggerMiddlewareModule.forRoot({
  skip: (req, res) => {
    // Skip both request and response logs for health checks
    if (req.path === "/health") return true;

    // Skip only response logs for successful requests
    if (res && res.statusCode < 400) {
      return { response: true };
    }

    return false;
  },
});

Apply to Specific Routes

LoggerMiddlewareModule.forRoot({
  routes: ["/api/*", "/admin/*"],
  logClientIp: true,
  logUserAgent: true,
});

License

MIT