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

request-vault-keeper

v1.0.10

Published

An enhanced HTTP logger with request/response body capture for debugging

Readme

🔒 request-vault-keeper

A comprehensive, configurable HTTP logging solution for Node.js applications.
Supports Express, NestJS, Fastify, Koa, and any Node.js HTTP server!


✨ Features

  • 🔌 Framework-agnostic: Works with Express, NestJS, Fastify, Koa, and raw Node.js HTTP servers
  • 📊 Multi-level logging: Choose from basic, detailed, or full logging verbosity
  • 🗄️ Multiple outputs: Console, file, and MongoDB storage options
  • 🔐 Security-focused: Built-in sensitive data masking for passwords, tokens, etc.
  • 🔍 Request tracing: Automatic correlation IDs for request tracking
  • 📦 Body capture: Intelligently captures and parses request/response bodies
  • 🧩 Customizable: Provide your own logging function for integration with existing systems
  • 📈 Performance: Optimized for high-throughput applications with configurable body size limits

📦 Installation

npm install request-vault-keeper
# or
yarn add request-vault-keeper

🚀 Usage

▶️ With Express

import express from 'express';
import { createHttpLogger } from 'request-vault-keeper';

const app = express();

// Basic usage with defaults
app.use(createHttpLogger());

app.get('/ping', (req, res) => {
  res.send('pong');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

▶️ With NestJS

// main.ts
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { createHttpLogger } from 'request-vault-keeper';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  
  // Apply the middleware globally
  app.use(createHttpLogger({
    format: 'json',
    logLevel: 'detailed'
  }));
  
  await app.listen(3000);
}
bootstrap();

▶️ With Fastify

import fastify from 'fastify';
import { HttpLogger } from 'request-vault-keeper';

const app = fastify();
const logger = new HttpLogger({ format: 'json' });

// Register as middleware (before routes)
app.addHook('onRequest', (request, reply, done) => {
  logger.middleware()(request.raw, reply.raw, done);
});

app.get('/ping', (request, reply) => {
  reply.send('pong');
});

app.listen({ port: 3000 }, (err) => {
  if (err) throw err;
  console.log('Server running on port 3000');
});

▶️ With Koa

import Koa from 'koa';
import Router from '@koa/router';
import { HttpLogger } from 'request-vault-keeper';

const app = new Koa();
const router = new Router();
const httpLogger = new HttpLogger();

// Convert middleware for Koa
app.use(async (ctx, next) => {
  await new Promise((resolve) => {
    httpLogger.middleware()(ctx.req, ctx.res, resolve);
  });
  await next();
});

router.get('/ping', (ctx) => {
  ctx.body = 'pong';
});

app.use(router.routes());

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

▶️ With Raw Node.js HTTP Server

import http from 'http';
import { createHttpLogger } from 'request-vault-keeper';

const logger = createHttpLogger({
  format: 'text',
  logLevel: 'basic'
});

const server = http.createServer((req, res) => {
  // Apply logger middleware
  logger(req, res);
  
  if (req.url === '/ping' && req.method === 'GET') {
    res.writeHead(200, { 'Content-Type': 'text/plain' });
    res.end('pong');
  } else {
    res.writeHead(404);
    res.end();
  }
});

server.listen(3000, () => {
  console.log('Server running on port 3000');
});

▶️ With Hapi

import Hapi from '@hapi/hapi';
import { HttpLogger } from 'request-vault-keeper';

const init = async () => {
  const server = Hapi.server({
    port: 3000,
    host: 'localhost'
  });
  
  const logger = new HttpLogger({ format: 'json' });
  
  // Register as extension (pre-handler)
  server.ext('onRequest', (request, h) => {
    logger.middleware()(request.raw.req, request.raw.res);
    return h.continue;
  });
  
  server.route({
    method: 'GET',
    path: '/ping',
    handler: () => 'pong'
  });
  
  await server.start();
  console.log('Server running on port 3000');
};

init();

▶️ Class-based approach

import express from 'express';
import { HttpLogger } from 'request-vault-keeper';

const app = express();

// Initialize logger with options
const logger = new HttpLogger({
  format: 'json',
  logToFile: true,
  logPath: './logs/app-http.log',
  logLevel: 'full'
});

// Use the middleware
app.use(logger.middleware());

app.get('/ping', (req, res) => {
  res.send('pong');
});

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

// Clean up when done
process.on('SIGINT', async () => {
  await logger.close();
  process.exit(0);
});

▶️ MongoDB Integration

import express from 'express';
import { HttpLogger } from 'request-vault-keeper';

const app = express();

// Initialize with MongoDB support
const logger = new HttpLogger({
  persistToDb: true,
  mongoUri: 'mongodb://localhost:27017',
  dbName: 'app_logs',
  collectionName: 'http_requests',
  logLevel: 'detailed'
});

app.use(logger.middleware());

// Start server, etc.

⚙️ Configuration Options

interface LoggerOptions {
  format?: "json" | "text";                  // Output format (default: "text")
  customLog?: (logData: any) => void;        // Custom logging function
  mongoUri?: string;                         // MongoDB connection string
  mongoOptions?: MongoClientOptions;         // MongoDB client options
  dbName?: string;                           // Database name (default: "logs_db")
  collectionName?: string;                   // Collection name (default: "http_logs")
  persistToDb?: boolean;                     // Enable MongoDB logging (default: false)
  logLevel?: "basic" | "detailed" | "full";  // Logging verbosity (default: "basic")
  maxBodySize?: number;                      // Max body size to log in bytes (default: 10000)
  sensitiveFields?: string[];                // Fields to mask (default: ['password', 'token', 'secret', 'authorization', 'apiKey'])
  logToConsole?: boolean;                    // Enable console output (default: true)
  logToFile?: boolean;                       // Enable file output (default: true)
  logPath?: string;                          // Path for log file (default: "../logs/http.log")
}

📊 Log Levels

  • basic: Method, URL, status code, response time, correlation ID
  • detailed: All basic data plus headers, query params, IP address, user agent (no bodies)
  • full: All detailed data plus request and response bodies

📤 Example Output

Text Format

[2025-04-22T14:30:45.123Z] f8d92-a52de GET /api/users 200 - 14.78ms

JSON Format

{
  "method": "GET",
  "url": "/api/users",
  "path": "/api/users",
  "query": { "page": "1", "limit": "10" },
  "statusCode": 200,
  "event": "finish",
  "responseTime": "14.78ms",
  "timestamp": "2025-04-22T14:30:45.123Z",
  "correlationId": "f8d92-a52de",
  "ip": "127.0.0.1",
  "userAgent": "Mozilla/5.0...",
  "requestHeaders": {
    "host": "localhost:3000",
    "authorization": "********"
  },
  "responseHeaders": {
    "content-type": "application/json",
    "content-length": "245"
  },
  "responseBody": {
    "data": [
      { "id": 1, "name": "John" },
      { "id": 2, "name": "Jane" }
    ],
    "pagination": {
      "total": 42,
      "page": 1
    }
  }
}

🧱 Framework Compatibility

| Framework | Supported | |-----------|-----------| | Express | ✅ | | NestJS | ✅ | | Fastify | ✅ | | Koa | ✅ | | Raw Node.js HTTP | ✅ | | Hapi | ✅ |


📘 License

MIT