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

nest-request-interceptor

v11.0.3

Published

## Overview

Readme

Nest Request Interceptor

Overview

nest-request-interceptor is a logging interceptor package for NestJS applications. It provides HTTP and RPC interceptors that log request and response details, including execution time, status codes, and error messages. The package also includes a decorator to skip logging when necessary.

Features

  • HTTPInterceptor: Logs HTTP requests and responses with status codes, execution times, and response sizes.
  • RPCInterceptor: Logs RPC requests and responses, including message patterns and execution times.
  • SkipLogging Decorator: Allows skipping logging for specific methods or controllers.
  • Custom Logging Utility: Uses ANSI color-coded console logs for better readability.

Installation

npm install nest-request-interceptor

Usage

Import the Interceptors

To enable logging for all requests in your NestJS application, register the interceptors globally.

import { Module } from '@nestjs/common';
import { APP_INTERCEPTOR } from '@nestjs/core';
import { HTTPInterceptor } from 'nest-request-interceptor';
import { RPCInterceptor } from 'nest-request-interceptor';

@Module({
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useClass: HTTPInterceptor,
    },
    {
      provide: APP_INTERCEPTOR,
      useClass: RPCInterceptor,
    },
  ],
})
export class AppModule {}

HTTP Server Bootstrap

For HTTP applications, register the HTTP interceptor in the main bootstrap function:

import { NestFactory, Reflector } from "@nestjs/core";
import { ValidationPipe } from "@nestjs/common";
import { AppModule } from "./app.module";
import { HTTPInterceptor } from "nest-request-interceptor";

async function bootstrapHttp() {
  const app = await NestFactory.create(AppModule);

  const reflector = app.get(Reflector); // Get the Reflector instance, use it to enable skipping logging feature
  app.useGlobalInterceptors(new HTTPInterceptor(reflector));
  app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));

  await app.listen(3000);
  console.log("HTTP server is running on: http://localhost:3000");
}

bootstrapHttp();

RPC Server Bootstrap

For microservices using RabbitMQ or another transport, register the RPC interceptor:

import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";
import { RPCInterceptor } from "nest-request-interceptor";
import { Transport, MicroserviceOptions } from "@nestjs/microservices";

async function bootstrapRpc() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(AppModule, {
    transport: Transport.RMQ,
    options: {
      urls: ["amqp://localhost:5672"],
      queue: "main_queue",
      queueOptions: { durable: false },
    },
  });

  app.useGlobalInterceptors(new RPCInterceptor());

  await app.listen();
  console.log("RPC server is running and connected to RabbitMQ");
}

bootstrapRpc();

Skip Logging for Specific Endpoints

Use the @SkipLogging() decorator to disable logging for specific methods or controllers.

import { Controller, Get } from '@nestjs/common';
import { SkipLogging } from 'nest-request-interceptor';

@Controller('example')
export class ExampleController {
  @Get()
  @SkipLogging()
  getData() {
    return { message: 'This request will not be logged' };
  }
}

Determines whether to skip logging (true to disable logging, false to keep logging active).

 import { Controller, Get } from "@nestjs/common";
 import { SkipLogging } from "./decorators/skip-logging";

 @Controller("users")
 export class UserController {

   // Logging is skipped for this method
   @Get("hidden")
   @SkipLogging()
   hiddenRoute() {
     return { message: "This request will not be logged" };
   }

   // Logging remains active for this method
   @Get("public")
   @SkipLogging(false)
   publicRoute() {
     return { message: "This request will be logged" };
   }
 }

Logging Format

The logs are color-coded for easy readability:

  • Blue: Incoming requests
  • Green: Successful responses
  • Yellow: Client errors (4xx)
  • Red: Server errors (5xx)

Example output:

[ 2025/02/25 14:30:00 ] - REQUEST GET /users
[ 2025/02/25 14:30:01 ] - SEND GET /users 200 45ms

API Reference

HTTPInterceptor

  • Logs HTTP requests and responses
  • Shows execution time and response status

RPCInterceptor

  • Logs RPC requests and responses
  • Captures message patterns and execution duration

SkipLogging

  • Decorator to disable logging on specific methods

License

MIT License