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

nestjs-pino-batch-http-transport

v1.3.3

Published

A NestJS module providing a Pino transport to batch logs and send them via HTTP, compatible with NestJS v11.

Downloads

148

Readme

NestJS Pino Batch HTTP Transport

A NestJS module that configures nestjs-pino to use a custom Pino transport for batching logs and sending them via HTTP. It uses axios directly for HTTP requests and pino-abstract-transport for efficient, out-of-process log handling.

Features

  • Batches logs before sending them via HTTP POST using axios.
  • Log processing occurs in a separate thread via pino-abstract-transport.
  • Conditionally adds pino-pretty to the transport pipeline in non-production environments if no other transport is specified by the user.
  • Highly configurable batch transport:
    • url: The target HTTP endpoint for logs.
    • batchSize: Maximum number of logs to send in a single batch (default: 100).
    • batchInterval: Maximum time in milliseconds to wait before sending a batch (default: 5000).
    • headers: Static headers to include in every HTTP request (e.g., for API keys).
    • axiosRequestTimeout: Timeout for the Axios HTTP request in milliseconds (default: 10000).
  • Graceful shutdown: Attempts to send any pending logs before the application exits.
  • Easy integration with NestJS applications via NestJsPinoBatchHttpModule.forRoot() for static configuration and NestJsPinoBatchHttpModule.forRootAsync() for dynamic/asynchronous configuration.

Installation

npm install nestjs-pino-batch-http-transport
# or
yarn add nestjs-pino-batch-http-transport

Ensure you also have nestjs-pino (and its peer pino-http) installed as per the nestjs-pino documentation. If you want to use pino-pretty in development (which is the default behavior of this module if the batch transport is enabled and no other transport is specified), install it as a dev dependency:

npm install --save-dev pino-pretty
# or
yarn add --dev pino-pretty

Usage

Import NestJsPinoBatchHttpModule into your application's root module. This module configures and provides the necessary options to nestjs-pino's LoggerModule internally.

Static Configuration

// app.module.ts
import { Module } from '@nestjs/common';
import { NestJsPinoBatchHttpModule } from 'nestjs-pino-batch-http-transport';

@Module({
  imports: [
    NestJsPinoBatchHttpModule.forRoot({
      // Optional pino-http options (passed to nestjs-pino)
      pinoHttp: {
        level: process.env.NODE_ENV !== 'production' ? 'debug' : 'info',
        // autoLogging: true, // Other pino-http options
      },
      
      // Configuration for the batch HTTP transport
      batchTransportConfig: {
        url: 'YOUR_LOGGING_ENDPOINT_URL', // Required
        batchSize: 100,                   // Optional, default: 100
        batchInterval: 5000,              // Optional, default: 5000ms
        headers: { 'X-API-KEY': 'YOUR_OPTIONAL_API_KEY' }, // Optional
        axiosRequestTimeout: 10000,       // Optional, default: 10000ms
      },

      enableTransport: process.env.NODE_ENV === 'production', // Default is false. Set to true for non local environments.
      enablePinoPretty: process.env.NODE_ENV !== 'production', // Default is true. Set to false for non local environments.
    }),
    // ... other modules
  ],
})
export class AppModule {}

Async Configuration (e.g., with NestJS ConfigService)

// app.module.ts
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { NestJsPinoBatchHttpModule, BatchHttpTransportConfig } from 'nestjs-pino-batch-http-transport';

@Module({
  imports: [
    ConfigModule.forRoot({ isGlobal: true }), // Your ConfigModule setup

    NestJsPinoBatchHttpModule.forRootAsync({
      imports: [ConfigModule], // Make ConfigModule available
      inject: [ConfigService],
      useFactory: async (configService: ConfigService) => {
        const batchConfig: BatchHttpTransportConfig = {
          url: configService.get<string>('LOGGING_ENDPOINT_URL'),
          batchSize: configService.get<number>('LOGGING_BATCH_SIZE', 100),
          batchInterval: configService.get<number>('LOGGING_BATCH_INTERVAL_MS', 5000),
          axiosRequestTimeout: configService.get<number>('LOGGING_AXIOS_TIMEOUT_MS', 10000),
          headers: {
            'X-App-Version': configService.get<string>('APP_VERSION', '1.0.0'),
            'X-API-KEY': configService.get<string>('LOGGING_API_KEY'),
          },
        };

        return {
          pinoHttp: {
            level: configService.get<string>('LOG_LEVEL', 'info'),
            // Other pino-http options...
          },
          batchTransportConfig: batchConfig,
          enableTransport: configService.get<boolean>('ENABLE_BATCH_LOGGING', true),
        };
      },
    }),
    // ... other modules
  ],
})
export class AppModule {}

License

MIT