prom-client

The de facto Prometheus client library for instrumenting Node.js applications with counters, gauges, histograms, and summaries.

Library
npm
v15.1.3
3,497 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
87 /100 Excellent
Development Activity 92
Maintenance 84
Community 72
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
75 /100 Good
Architecture 80
Code Quality 88
Innovation 78
Learning Curve 55

prom-client is a Node.js library for exposing application metrics in the Prometheus exposition format. It implements the four core Prometheus metric types — Counter, Gauge, Histogram, and Summary — along with a Registry that collects and serializes them into the text format Prometheus scrapes over HTTP. It does not bundle a web framework of its own; instead, applications wire register.metrics() into whatever HTTP server or framework they already use to expose a /metrics endpoint.

Beyond custom metrics, the library ships collectDefaultMetrics() for automatic collection of Node.js and process-level signals recommended by Prometheus itself — event loop lag, active handles, garbage collection duration, heap and memory usage, process CPU time, open file descriptors, and Node.js version. For multi-process deployments it provides cluster and worker-thread aggregation registries that merge metrics across workers with configurable aggregation strategies (sum, min, max, average, first, or omit), plus a Pushgateway client for batch/cron-style jobs that can’t be scraped directly.

The project began life as prom-client and has since been adopted as the official Node.js client under the Prometheus GitHub organization (now published as @prometheus-io/client, with prom-client preserved as the long-standing, widely-depended-upon package name most of the ecosystem still installs). It supports both the legacy Prometheus text exposition format and the newer OpenMetrics format, including OpenMetrics exemplars tied to OpenTelemetry trace and span IDs.

What You Get

  • Counter, Gauge, Histogram, and Summary metric types with full label support, including strongly-typed labels via TypeScript’s as const
  • collectDefaultMetrics() for automatic Node.js/process metrics: event loop lag and utilization, GC duration, heap and memory stats, CPU time, file descriptors, and version info
  • Multi-registry support so different parts of an application (or different metric sets) can be scraped independently, plus a Registry.merge() to combine them on one endpoint
  • Cluster and worker-thread aggregation registries with per-metric aggregator strategies (sum, min, max, average, first, omit) for accurate metrics across multiple Node.js processes
  • Pushgateway client for pushing metrics from short-lived or batch jobs that Prometheus can’t scrape directly
  • Dual exposition format support — classic Prometheus text format and OpenMetrics, including OpenMetrics exemplars linked to OpenTelemetry trace/span IDs

Common Use Cases

  • Exposing a /metrics endpoint from an Express, Fastify, or plain http.Server-based Node.js API for Prometheus to scrape
  • Tracking HTTP request duration and count with labeled Histograms to power latency/error-rate dashboards and SLO alerts
  • Monitoring Node.js runtime health (event loop lag, GC pauses, memory growth) to catch performance regressions before they page someone
  • Aggregating metrics across a Node.js cluster or worker-thread pool so a single scrape reflects the whole process group, not just one worker
  • Pushing job-completion metrics from cron jobs or one-off scripts via the Pushgateway client, since those processes exit before Prometheus can scrape them

Under The Hood

Architecture

The library centers on a Registry (lib/registry.js) that metrics register themselves into at construction time, and an abstract Metric base class (lib/metric.js) that Counter, Gauge, Histogram, and Summary each extend — validating names and label names up front and throwing on misconfiguration rather than failing silently later. ClusterRegistry and WorkerRegistry (lib/cluster.js, lib/worker.js) extend this model across process boundaries, using IPC to collect and merge metric snapshots from workers according to a per-metric aggregator strategy defined in lib/metricAggregators.js. Pushgateway (lib/pushgateway.js) is a separate, self-contained concern layered on top of the same Registry abstraction rather than woven into it, and shared low-level exposition-format and escaping logic lives in lib/util.js. The design favors flat, single-responsibility modules over deep class hierarchies or a plugin system, which keeps the failure surface small and each file’s job easy to state in one sentence.

Tech Stack

The implementation is plain JavaScript with hand-written TypeScript declarations (index.d.ts, ~900 lines) rather than a compiled TypeScript source — tsc is used only to type-check the codebase, not to build it. Runtime dependencies are deliberately minimal: @opentelemetry/api (only exercised when OpenMetrics exemplars are enabled) and tdigest (for the sliding-window quantile estimation behind Summary metrics). Tooling is modern and actively maintained: ESLint 10 with typescript-eslint, eslint-plugin-n, and eslint-plugin-jsdoc, Prettier for formatting, Husky plus lint-staged for pre-commit enforcement, and GitHub Actions workflows for CI, changelog generation, and release automation. The package targets current Node.js LTS lines only, reflecting its role as low-level, performance-sensitive infrastructure rather than a broadly polyfilled utility library.

Code Quality

Every core module in lib/ has a corresponding test file under test/ (counterTest.js, gaugeTest.js, histogramTest.js, summaryTest.js, registerTest.js, clusterTest.js, workerTest.js, pushgatewayTest.js, validationTest.js, utilTest.js, aggregatorsTest.js, timeWindowQuantilesTest.js, plus a dedicated typescript.ts file that exercises the type definitions themselves), run via Jest with coverage collection wired into the test script. Constructors validate their inputs eagerly — missing help text, missing names, invalid metric or label names, and invalid content types all throw immediately rather than producing malformed output downstream. Naming is consistent and domain-accurate throughout (Registry, Metric, Grouper, aggregators), and the codebase is fully linted and Prettier-formatted with pre-commit enforcement, giving high confidence in consistency across contributors.

What Makes It Unique

Most metrics client libraries stop at exposing counters and gauges from a single process. prom-client’s cluster/worker aggregation layer — where each metric declares its own aggregation strategy (sum, min, max, average, first, or omit) and a primary process merges snapshots from all workers over IPC — solves a problem that’s genuinely awkward to get right in Node.js’s multi-process model, and is unusual to see handled this thoroughly in a client library rather than left to the operator. Layered on top of that is dual-format support for both the legacy Prometheus text format and the OpenMetrics standard, including exemplars that attach OpenTelemetry trace and span IDs directly to counter and histogram observations — connecting metrics to distributed traces at the data-model level rather than through a separate correlation step.

Used by 31 apps in this directory

TypeScript
91%
AGPL 3.0

OpenPanel

Analytics

7,187

Open-source Mixpanel alternative with session replay, MCP integration, and privacy-first product analytics you fully control.

View details
83
Repo Health
74
Technical
64
Dependency
Built with
TypeScript 91%
Updated 6 days ago
TypeScript
54%
Other

OpenReplay

Analytics

13,042

Self-hosted session replay and product analytics suite that lets you see exactly what users do on your web app — without sending data to third parties.

View details
91
Repo Health
77
Technical
66
Dependency
Built with
TypeScript 54%
Go 13%
Updated 6 days ago
JavaScript
64%
AGPL 3.0

overleaf

Collaboration · Productivity

18,266

Open-source, real-time collaborative LaTeX editor with sandboxed compilation and full TeXLive support for self-hosted academic and research teams.

View details
84
Repo Health
80
Technical
59
Dependency
Built with
JavaScript 64%
TypeScript 30%
Updated 1 months ago
TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago
TypeScript
97%
Other

Rocket.Chat

Team Chat

46,304

The secure, self-hosted team communications platform for organizations that cannot compromise on data sovereignty.

View details
96
Repo Health
79
Technical
63
Dependency
Built with
TypeScript 97%
Updated 5 days ago
Python
100%
Other

Sourcebot

AI Code Assistants · Developer Tools · Search

4,005

A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.

View details
86
Repo Health
83
Technical
61
Dependency
Built with
Python 100%
Updated 1 weeks ago
TypeScript
98%
Apache 2.0

Tianji

Analytics · Monitoring

3,119

Replace Google Analytics, UptimeKuma, and Prometheus with one self-hosted platform that tracks websites, monitors uptime, and reports server health.

View details
86
Repo Health
76
Technical
64
Dependency
Built with
TypeScript 98%
Updated 6 days ago
HTML
68%
AGPL 3.0

ToolJet

AI Agents · Low Code Platforms · No Code Platforms

41,123

Open-source AI-native platform to build and deploy internal tools, workflows, and AI agents with a visual drag-and-drop builder and 80+ data source integrations.

View details
94
Repo Health
81
Technical
63
Dependency
Built with
HTML 68%
JavaScript 20%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers