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

api-health-middleware

v1.0.3

Published

Express middleware to report per-request API health to a monitoring backend

Readme

API-Monitor-Middleware

npm version License Downloads

A lightweight Express middleware to automatically monitor API health.
It tracks requests, responses, errors, response time, and uptime, sending logs to your dashboard (Under Development) using an API key.

This package is plug-and-play — just install it, provide your API key, and it works out-of-the-box.


Features

  • Automatic logging of all API requests
  • Tracks:
    • Endpoint (/api/users, /login, etc.)
    • HTTP method (GET, POST, PUT, DELETE)
    • Status code (200, 404, 500, etc.)
    • Response time in milliseconds
    • Success / error messages
    • IP address and User-Agent
  • Works with Express 4.x and above

Installation

npm i api-health-middleware

Usage
1. Import and Initialize Middleware
const express = require('express');
const app = express();

// Import health monitor middleware
const healthMonitor = require('api-health-middleware');

// Use middleware globally
app.use(
  healthMonitor({
    apiKey: 'YOUR_DASHBOARD_API_KEY', // Required
  })
);

app.get('/api/users', (req, res) => {
  res.json({ message: 'Hello users' });
});

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

2. How It Works

Middleware intercepts every request and response.

Captures metrics: endpoint, method, status, response time, IP, User-Agent.

Sends logs asynchronously to your monitoring dashboard using the API key.

Your dashboard aggregates metrics per project, showing:

Total API calls

Error count

Average response time

Uptime percentage

3. Middleware Configuration Options
Option	Type	Required	Default	Description
apiKey	string	✅ Yes	—	API key generated from your dashboard for authentication
Example Log Object Sent to Dashboard
{
  "timestamp": "2026-02-11T16:24:00.123Z",
  "method": "GET",
  "endpoint": "/users",
  "statusCode": 200,
  "responseTimeMs": 123,
  "success": true,
  "errorMessage": null,
  "ip": "192.168.0.1",
  "userAgent": "PostmanRuntime/7.28.4",
  "projectId": "623d2f6b9e1b0a0012345678"
}

Example Metrics from Dashboard

Total API calls: 120

Error count: 5

Average response time: 135 ms

Uptime: 95.83%

Best Practices

Async logging – middleware sends logs asynchronously to avoid blocking API responses.


Use environments – differentiate production, staging, or development metrics.

Batch logs – optionally batch logs to reduce network calls.

Secure API key – never commit it publicly.

Contributing

We welcome contributions!

Fork the repo

Create a new branch (feature/my-feature)

Run tests:

npm test


Submit a pull request

License

MIT © Your Name

Acknowledgements

Inspired by Postman Monitors and lightweight API monitoring systems.


---