Registry / observability / express-metrics-middleware

express-metrics-middleware

JSON →
library0.1.14jsnpmunverified

Express middleware that automatically collects standard Prometheus metrics (HTTP request duration, request count, active connections, etc.) for Node.js applications. Version 0.1.14 is the current stable release, updated infrequently. Compared to prom-client or express-prom-bundle, this package offers a zero-configuration setup with sensible defaults and built-in TypeScript types. It is opinionated and designed for quick integration without manual metric definition, but may have limited customization options.

npm install express-metrics-middleware
INSTALL
IMPORT
SIG · EXPRESS-METRICS-MI
E
express-metrics-middleware
observabilityjavascriptv0.1.14
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createMiddleware
import { createMiddleware } from 'express-metrics-middleware'
import createMiddleware from 'express-metrics-middleware'
Named export, not default. TypeScript types are included.
MetricsConfig
import type { MetricsConfig } from 'express-metrics-middleware'
TypeScript only; use import type for type-only import.
createMiddleware (require)
const { createMiddleware } = require('express-metrics-middleware')
const createMiddleware = require('express-metrics-middleware')
CommonJS: destructure the require because it's a named export.

Shows how to create an Express server with the middleware that collects Prometheus metrics automatically.

import express from 'express'; import { createMiddleware } from 'express-metrics-middleware'; const app = express(); app.use(createMiddleware({ metricPrefix: 'my_app' })); app.get('/hello', (req, res) => { res.send('hello world'); }); app.listen(3000, () => { console.log('Server running on port 3000'); }); // Metrics endpoint is automatically exposed at /metrics by default
Debug
Known issues
gotchaThe middleware exposes a /metrics endpoint by default; ensure it does not conflict with your routes or middleware order (place it before authentication if metrics should be public).
fix
Route /metrics explicitly with your own handler if you need custom behavior.
affects: >=0.1.0
breakingIn version 0.1.0, the function was named 'metricsMiddleware' and exported as default. In 0.1.1+ it changed to named export 'createMiddleware'.
fix
Use import { createMiddleware } from 'express-metrics-middleware' instead.
affects: 0.1.0
gotchaThe middleware relies on prom-client's default metrics (collectDefaultMetrics) which may increase memory usage in long-lived processes. Disable if not needed via options.
fix
Pass { collectDefaultMetrics: false } to createMiddleware.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: createMiddleware is not a function
Using default import instead of named import.
fix
Use import { createMiddleware } from 'express-metrics-middleware'
Cannot find module 'prom-client' or its corresponding type declarations.
Missing peer dependency prom-client.
fix
Run npm install prom-client
Metrics endpoint returns 404
Middleware not registered or route conflict.
fix
Ensure app.use(createMiddleware()) is called before other routes.
Upgrade
Version history
0.1.14latest on npm
Audit
Dependencies
prom-clientrequiredprovides the Prometheus client library for metrics collection and exposition
expressrequiredExpress is required as it is Express middleware
Agent activity
15 hits · last 30 days
node
12
OpenAI (training)
3
Resources
express-metrics-middleware — npm install express-metrics-middleware · libregistry