Prometheus client_js: Node Metrics Client Review
Use `@prometheus-io/client` to instrument a Node.js service whose metrics will be scraped in Prometheus/OpenMetrics format; skip it if you expect an all-in-one monitoring server or a bundled HTTP endpoint. Checked against v0.16.1 on 2026-11-15; Apache-2.0; its declared Node range is `^22 || ^24 || >=26`; the latest release is dated 2026-08-27 and an export proposal was opened 2026-11-15. [S2–S5, S7]
Understanding the Prometheus Node.js Client
`@prometheus-io/client` is an instrumentation library, not the Prometheus server: create metrics, collect values, and serve `await registry.metrics()` from a route in your own HTTP application. The README explicitly says no web framework is bundled. The documented installation command is `npm install @prometheus-io/client`. [S2]
Core Features for Node.js Application Monitoring
- ✓Create Counter, Gauge, Histogram, and Summary metrics for Prometheus/OpenMetrics exposition. [S2]
- ✓Collect default Node.js process metrics through the registry. [S2]
- ✓Expose registry output using `await registry.metrics()` from an application-owned route. [S2]
- ✓Supports aggregation with Node.js’s cluster module. [S2]
Getting Started with Prometheus client_js
Install the package with `npm install @prometheus-io/client`. Expose the result of `await registry.metrics()` from a route in your own HTTP application; the library does not bundle a web framework or endpoint. [S2]
Instrumenting Your Node.js Application with Metrics
The basic loop is: create a metric with a mandatory `name` and `help`, call `.inc()`/`.set()`/`.observe()` on it as your code runs, then answer Prometheus's scrape request with `await registry.metrics()` from whatever HTTP handler you're already running — the library doesn't bundle a web framework, so that route is yours to wire up. For values you can only read at scrape time, like current memory usage rather than something accumulated continuously, pass a `collect()` function instead of updating the metric on a timer; the README is specific that `collect()` — sync or async — fires when the registry gathers values, and a `setInterval` callback is the wrong place for those writes. Labels come from a `labelNames` array on the metric config, then get filled in through `.labels(...).set(...)` or by passing a labels object as the first argument to a call like `.inc()`. Running under Node.js's `cluster` module changes the picture: a worker's local registry only reflects that worker's own numbers, so you instantiate `ClusterRegistry` before branching on `cluster.isPrimary`. Skipping that setup in a worker leaves it unable to answer when the primary asks it to aggregate, so `clusterMetrics()` just stalls until it times out. Custom metrics sum across workers by default; set `aggregator` in the metric config to `'first'`, `'min'`, `'max'`, `'average'`, or `'omit'` when summing isn't the right combination for that particular metric.
Strengths
- ✓Provides the standard metric types used by Node.js services. [S2]
- ✓The registry supports Prometheus and OpenMetrics exposition formats. [S2]
- ✓Supports aggregation with Node.js’s cluster module. [S2]
Considerations and Known Limitations
- △The library does not bundle a web framework or HTTP endpoint; the application must expose registry output from its own route. [S2]
- △The declared supported Node.js versions are `^22 || ^24 || >=26`. [S3]
- △Default file-descriptor and memory metrics are Linux-only. [S2]
- △Cluster aggregation averages event-loop lag readings across workers, which is less precise than summing other metrics. [S2]
- △Combining registries with different exposition formats has behavior the README describes as undefined. [S2]
Alternatives for Node.js Metrics Collection
Frequently Asked Questions
Prometheus client for Node.js is released under the Apache-2.0 license, as listed on its GitHub repository.
Prometheus client for Node.js ships a ClusterRegistry that aggregates metrics from every worker into the primary process, since a worker's own registry only reflects its local numbers by default.
Prometheus client for Node.js includes a Pushgateway client with pushAdd, push, and delete methods, plus a requireJobName option for gateways like Gravel Gateway that skip job-name grouping.
Prometheus client for Node.js supports four metric types: Counter, Gauge, Histogram, and Summary.
Prometheus client for Node.js can emit the OpenMetrics 1.0.0 exposition format per registry, alongside the classic Prometheus 0.0.4 text format it defaults to.
Prometheus client for Node.js does have OS-specific metrics: its default file-descriptor and memory readings are only available on Linux, per the README.
The problem it solves
A Node.js process that's slow or failing under load won't tell you why unless something inside it is counting requests, timing them, and tracking memory and event-loop health in a format your monitoring stack can actually scrape. Hand-rolling that layer — picking histogram bucket boundaries, formatting Prometheus's exposition text by hand, keeping Counters from ever going backward — is easy to get subtly wrong. prometheus/client_js exists to standardize that instrumentation layer instead of every team inventing its own metric-naming and formatting conventions.
Best use cases
- •Instrumenting a Node.js HTTP API with request-count Counters and request-duration Histograms that a Prometheus server scrapes on an interval.
- •Aggregating metrics across a Node.js `cluster` deployment where each worker would otherwise only expose its own local numbers.
- •Correlating metrics with distributed traces by attaching exemplars to Counters and Histograms once OpenTelemetry is populating trace and span IDs.
- •Pushing metrics from short-lived batch or cron jobs to a Pushgateway instead of standing up a long-lived process for Prometheus to scrape.
- •Moving a registry from the classic Prometheus text format to OpenMetrics without rewriting the metric-type code that produces the values.
Who should try it — and who should skip
Node.js teams that want Counter, Gauge, Histogram, or Summary metrics in a format their Prometheus-compatible scraper can collect, and whose runtime matches the package’s declared Node range (`^22 || ^24 || >=26`). [S2, S3] Version 0.16 changed the published package name from `prom-client` to `@prometheus-io/client` and includes breaking changes; check imports and worker/cluster setup before upgrading an existing deployment. [S5, S6] An open issue and its related pull request propose yielding the event loop during metric export; that work is not part of v0.16.1. [S7]
Related repositories
Curious whether client_js is right for you?
Let ChatGPT, Claude, or Perplexity look into it — click below and see what AI actually says about client_js.
