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

@metriq/nestjs

v0.5.0

Published

NestJS adapter for Metriq - high-performance TypeScript metrics collection library

Downloads

11

Readme

@metriq/nestjs

npm version License

NestJS adapter for Metriq metrics library.

📦 Installation

npm install @metriq/nestjs

🚀 Quick Start

// app.service.ts
import { Injectable } from "@nestjs/common";
import { Counter, Metrics } from "metriq";
import { InjectMetriq } from "@metriq/nestjs";

@Injectable()
export class AppService {
    private readonly counter: Counter;

    constructor(
        // Inject the Metriq service
        @InjectMetriq() readonly metrics: Metrics,
    ) {
        // Create a counter
        this.counter = metrics.createCounter("http_requests_total", "Total HTTP requests");
    }

    // ...
    // Use the counter via this.counter
}

// app.module.ts
import { Module } from "@nestjs/common";
import { MetriqModule, MetricsController } from "@metriq/nestjs";
import { AppService } from "./app.service";

@Module({
    imports: [
        // Initialize the Metriq module
        MetriqModule.forRoot(),
    ],
    controllers: [
        // Add the metrics endpoint controller, it defaults to /metrics
        MetricsController,
    ],
    providers: [AppService],
})
export class AppModule {}

// main.ts
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./app.module";

async function bootstrap() {
    const app = await NestFactory.create(AppModule);
    await app.listen(3000);
}

void bootstrap();

🔧 Request Monitoring Example

// app.interceptor.ts
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from "@nestjs/common";
import { Request, Response } from "express";
import { Observable, tap } from "rxjs";
import { Counter, Histogram, Metrics } from "metriq";
import { InjectMetriq } from "@metriq/nestjs";

type RequestLabels = { method: string; path: string; status: string };
type RequestLatencyLabels = { method: string; path: string };

@Injectable()
export class AppInterceptor implements NestInterceptor {
    private readonly requests: Counter<RequestLabels>;
    private readonly latency: Histogram<RequestLatencyLabels>;

    constructor(@InjectMetriq() metrics: Metrics) {
        // Create metrics
        this.requests = metrics.createCounter<RequestLabels>("http_requests_total", "Total HTTP requests");

        this.latency = metrics.createHistogram<RequestLatencyLabels>(
            "http_request_duration_seconds",
            "Request duration in seconds",
            {
                buckets: [0.1, 0.5, 1, 2, 5],
            },
        );
    }

    // Interceptor to track requests and latency
    intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {
        const http = context.switchToHttp();
        const req = http.getRequest<Request>();
        const res = http.getResponse<Response>();
        const start = process.hrtime();

        return next.handle().pipe(
            tap(() => {
                const [seconds, nanoseconds] = process.hrtime(start);
                const duration = seconds + nanoseconds / 1e9;

                const labels = {
                    method: req.method,
                    path: req.route?.path ?? "unknown",
                    status: res.statusCode.toString(),
                };

                this.requests.increment(labels);
                this.latency.observe(
                    {
                        method: labels.method,
                        path: labels.path,
                    },
                    duration,
                );
            }),
        );
    }
}

// app.module.ts
import { Module } from "@nestjs/common";
import { MetriqModule, MetricsController } from "@metriq/nestjs";
import { APP_INTERCEPTOR } from "@nestjs/core";
import { AppInterceptor } from "./app.interceptor";

@Module({
    imports: [
        // Initialize the Metriq module
        MetriqModule.forRoot(),
    ],
    controllers: [
        // Add the metrics endpoint controller, it defaults to /metrics
        MetricsController,
    ],
    providers: [
        {
            // Add the interceptor to the app
            provide: APP_INTERCEPTOR,
            useClass: AppInterceptor,
        },
    ],
})
export class AppModule {}