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

data-for-logs

v4.0.6

Published

Structured HTTP request/response snapshots for logging (NestJS, Express, raw Node http)

Downloads

1,205

Readme

data-for-logs

Structured HTTP request/response snapshots for server logging and observability.
Works with raw Node http, Express, and NestJS (Express adapter).

Captures everything useful from a request and its response — URL, query, params,
headers, body, IP, timing, status — with automatic redaction of secrets.


Installation

npm install data-for-logs

What you get in every log payload

{
  "timestamp": "2026-04-02T12:00:00.000Z",
  "event": "finish",
  "durationMs": 12.4,
  "request": {
    "method": "POST",
    "url": "/auth/login",
    "originalUrl": "/auth/login",
    "path": "/auth/login",
    "route": "/auth/login",
    "query": {},
    "params": {},
    "headers": {
      "content-type": "application/json",
      "authorization": "[REDACTED]"
    },
    "body": {
      "email": "[email protected]",
      "password": "[REDACTED]"
    },
    "ip": "203.0.113.10",
    "remoteAddress": "::ffff:127.0.0.1",
    "requestId": "x-request-id value (or correlation-id / traceparent)",
    "userAgent": "...",
    "contentType": "application/json"
  },
  "response": {
    "statusCode": 201,
    "statusMessage": "Created",
    "headers": { "content-type": "application/json" },
    "headersSent": true,
    "finished": true
  }
}

Usage in NestJS

1. Create the middleware file

// src/http-log.middleware.ts
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { createMiddleware } from 'data-for-logs';

const logMiddleware = createMiddleware(
  (_err, payload) => {
    console.log(JSON.stringify(payload)); // replace with your logger / Kafka producer
  },
  {
    includeBody: true,
    highResTime: () => performance.now(),
    redactBodyKeys: ['pin', 'otp', 'card_number'], // merged with built-in list
  },
);

@Injectable()
export class HttpLogMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    logMiddleware(req, res, next);
  }
}

2. Register it globally in AppModule

// src/app.module.ts
import { Module, NestModule, MiddlewareConsumer } from '@nestjs/common';
import { HttpLogMiddleware } from './http-log.middleware';

@Module({ /* ... */ })
export class AppModule implements NestModule {
  configure(consumer: MiddlewareConsumer) {
    consumer
      .apply(HttpLogMiddleware)
      .forRoutes('*'); // or specific controllers / paths
  }
}

3. Or register globally in main.ts (before routes)

// src/main.ts
import { createMiddleware } from 'data-for-logs';

const app = await NestFactory.create(AppModule);
app.use(createMiddleware((_err, payload) => logger.log(payload)));
await app.listen(3000);

API

createMiddleware(handler, options?)

Returns a ready-made (req, res, next) => void middleware function.
This is the recommended entry point for Nest / Express.

const mw = createMiddleware((_err, payload) => {
  kafkaProducer.send({
    topic: 'http-logs',
    messages: [{ value: JSON.stringify(payload) }],
  });
});

onResponseComplete(req, res, handler, options?)

Low-level hook. Fires handler exactly once when the response ends.
Returns a function you can call to force completion early (manual event).

const flush = onResponseComplete(req, res, (_err, payload) => {
  console.log(payload);
});
// flush(); // force early if needed

getRequestSnapshot(req, options?)

Returns the request snapshot immediately (no waiting for response).
Useful inside route handlers or interceptors.

const snap = getRequestSnapshot(req, { includeBody: true });

getResponseSnapshot(res)

Returns the response snapshot. Call after res.end() for complete data.

const snap = getResponseSnapshot(res);

Options

| Option | Type | Default | Description | |---|---|---|---| | includeBody | boolean | true | Include req.body in the snapshot | | includeRawBody | boolean | false | Include req.rawBody (if your middleware sets it) | | redactSensitiveHeaders | boolean | true | Redact authorization, cookie, set-cookie, x-api-key, proxy-authorization | | redactBodyKeys | string[] | null | Extra body keys to redact (merged with built-in list) | | maxBodyDepth | number | 8 | Max depth when cloning body | | maxBodyKeys | number | 200 | Max object keys per level | | maxArrayElements | number | 100 | Max array items to include | | maxStringLength | number | 10000 | Truncate strings longer than this | | highResTime | () => number | Date.now | Use performance.now() for sub-ms timing | | onHandlerError | (err) => void | — | Called if your handler throws |


Built-in redacted body keys

password, passwd, secret, token, access_token, refresh_token, authorization, credit_card, creditcard, cvv, ssn

Add more via redactBodyKeys option. All comparisons are case-insensitive.


event values

| Value | Meaning | |---|---| | finish | Response sent normally | | close | Client disconnected before response finished | | manual | You called the returned flush function early |


License

ISC