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 🙏

© 2025 – Pkg Stats / Ryan Hefner

traceit-express

v0.1.7

Published

Lightweight request and error logging middleware for Express.

Readme

🚀 traceit-express

A lightweight, plug-and-play logging middleware for Express.
Tracks request performance, API failures, and runtime errors — with clean structured logs and pluggable storage (MongoDB by default).

Built to be fast, minimal, and production-ready.


✨ Features

  • ⚡ Zero-config Express request logger
  • 🛠 Full error logger with message + stack trace
  • 🧩 Works with your existing mongoose instance
  • 🔌 Pluggable storage (Mongo, file, SQL, HTTP, custom)
  • 🚦 Detect slow requests (configurable threshold)
  • 📊 Skip un-required status-codes
  • 🕵 Mask sensitive fields (password, token, etc.)
  • 🆔 Automatic unique request IDs
  • 💡 Clean console output (optional)
  • 🔇 Silent and safe — never crashes your app

📦 Installation

npm install traceit-express

⚡ Quick Start

const express = require("express");
const mongoose = require("mongoose");

const { requestLogger, errorLogger } = require("traceit-express");
const mongoStorage = require("traceit-express/storage/mongoStorage");

mongoose.connect(process.env.MONGO_URI);

const app = express();
const storage = mongoStorage(mongoose);

app.use(requestLogger({ mongoose, storage }));
app.use(errorLogger({ mongoose, storage }));

app.listen(3000, () => console.log("Server running"));

🧩 What gets logged

Request logs

  • Method
  • Route
  • Status
  • Duration (ms)
  • IP
  • User-agent
  • Body (optional)
  • Query + params
  • User context (if present)
  • Request ID
  • Timestamp

Error logs

Everything above plus:

  • Error message
  • Error stack trace

⚙️ Configuration Options

requestLogger({
  product_id: "my-service",
  slowThreshold: 10000,       // mark requests slower than 10s
  ignoreRoutes: ["/health"],
  ignoreStatusCodes: [304],
  maskFields: ["password", "token"],
  logRequestBody: false,
  enableConsole: true,        // pretty console output
  mongoose,
  storage
});

🔌 Using MySQL as Storage

  1. Database Connection Module
const mysql = require("mysql2/promise");

const createDB = async () => {
  const db = await mysql.createConnection(process.env.MYSQL_URL);
  console.log("MySQL connected");
  return db;
};

module.exports = { createDB };
  1. Integration in Application
createDB().then((db) => {
  const storage = sqlStorage(db);
  app.use(
    requestLogger({
      mongoose,
      storage,
      enableConsole: true,
    })
  );
});

🕵 Console Output Example

GET /api/users → 200 (12ms)
POST /api/login → 400 (3ms)
GET /api/reports → 200 (12033ms) SLOW

🗂 Example Log (MongoDB)

{
  "product_id": "my-service",
  "requestId": "req_18f3c2e7a9b1",
  "method": "GET",
  "route": "/api/orders",
  "status": 500,
  "duration": 8,
  "ip": "::1",
  "ua": "Mozilla/5.0",
  "query": {},
  "params": {},
  "error": {
    "message": "Test Error",
    "stack": "Error: Test Error..."
  },
  "createdAt": "2025-11-14T10:33:12.124Z"
}

🤝 Contributing

Contributions, improvements, and new storage adapters are welcome.


📄 License

MIT License © 2025