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

monten

v0.1.5

Published

Lightweight observability utilities for Express-based Node.js backends (experimental).

Readme


⚠️ Experimental: APIs and behavior may change in minor versions. Use with caution in critical systems.

Features

| Feature | Description | | ------------------------- | ----------------------------------------------------- | | 🕐 HTTP Timing | Measure total request latency with drop-in middleware | | 📊 Error Tracking | Automatic error rate tracking with stack traces | | 🗄️ DB Timing | Explicit instrumentation via withDbTiming helper | | 🔗 Request Context | Per-request scoping with AsyncLocalStorage | | 📝 Structured Logging | JSON-only logs with requestId correlation | | 📦 Metrics Batching | In-memory buffer with periodic flushing | | 🔌 Zero Coupling | Fully removable without breaking your app |

Technologies

| Technology | Purpose | | --------------------- | ---------------------------------------------------- | | TypeScript | Type-safe implementation with full declaration files | | Node.js | Runtime environment (v18+) | | AsyncLocalStorage | Native request-scoped context propagation | | Express | Compatible middleware architecture | | JSON | Structured logging format |

Installation

npm install monten
yarn add monten
pnpm add monten

Quick Start

import express from 'express'
import { initObservability, monten } from 'monten'

const app = express()

// Initialize observability
initObservability({
  serviceName: 'users-service',
  enableLogging: true,
  enableMetrics: true,
})

// Add middleware (single line!)
app.use(monten())

app.get('/health', (_req, res) => {
  res.status(200).json({ ok: true })
})

app.listen(3000)

Database Timing

Use withDbTiming to measure any async operation — works with Prisma, Sequelize, raw SQL, Redis, HTTP calls, etc.

import { withDbTiming } from 'monten'
import { prisma } from './prismaClient'

app.get('/users/:id', async (req, res, next) => {
  try {
    const user = await withDbTiming(() =>
      prisma.user.findUnique({ where: { id: req.params.id } })
    )

    if (!user) {
      return res.status(404).json({ error: 'Not found' })
    }

    res.json(user)
  } catch (err) {
    next(err)
  }
})

API Reference

initObservability(config)

Initialize the observability system. Call once at app startup.

initObservability({
  serviceName: 'my-service', // Service identifier in logs/metrics
  enableLogging: true, // Enable structured JSON logging
  enableMetrics: true, // Enable metrics collection & flushing
  metricsFlushIntervalMs: 10000, // Optional: flush interval (default: 10s)
})

monten()

Express middleware that captures request timing, errors, and emits logs/metrics.

app.use(monten())

withDbTiming<T>(fn: () => Promise<T>): Promise<T>

Wrap any async function to measure its duration and accumulate it in the request context.

const result = await withDbTiming(() => db.query('SELECT * FROM users'))

Log Output

Each request produces a structured JSON log entry:

{
  "level": "info",
  "message": "http_request",
  "timestamp": 1704307200000,
  "serviceName": "users-service",
  "requestId": "550e8400-e29b-41d4-a716-446655440000",
  "fields": {
    "method": "GET",
    "path": "/users/123",
    "statusCode": 200,
    "latencyMs": 45,
    "dbTimeMs": 12
  }
}

Architecture

┌─────────────────────────────────────────────────────────┐
│                    Express App                          │
├─────────────────────────────────────────────────────────┤
│  monten()                                              │
│  ┌───────────────────────────────────────────────────┐  │
│  │  AsyncLocalStorage Context                        │  │
│  │  • requestId                                      │  │
│  │  • startTimeMs                                    │  │
│  │  • dbTimeMs (accumulated)                         │  │
│  └───────────────────────────────────────────────────┘  │
├─────────────────────────────────────────────────────────┤
│  Route Handlers                                         │
│  └─> withDbTiming(() => prisma.user.find(...))         │
├─────────────────────────────────────────────────────────┤
│  On Response Finish:                                    │
│  • Structured JSON log → stdout                         │
│  • Metric record → in-memory buffer                     │
├─────────────────────────────────────────────────────────┤
│  Background Flusher (setInterval)                       │
│  • Drains buffer periodically                           │
│  • Sends to pluggable sink                              │
└─────────────────────────────────────────────────────────┘

Removing the Library

This library is designed to be fully removable:

  1. Remove initObservability() call
  2. Remove app.use(monten())
  3. Remove withDbTiming() wrappers (just call the inner function directly)

Your application will continue to function normally.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

License

MIT © 2026