{"library":"prom-client","title":"Prometheus Client for Node.js","description":"Prometheus client for Node.js (`prom-client`) is a comprehensive toolkit for instrumenting Node.js applications with Prometheus metrics. It supports all standard Prometheus metric types including counters, gauges, histograms, and summaries, alongside OpenMetrics and Exemplars which were introduced in version 15.0.0. The package is currently stable at version 15.1.3, with a release cadence that sees frequent patch and minor updates addressing bugs and adding features, while major versions are released less often to accommodate significant changes like Node.js version support adjustments and new Prometheus protocol features. Key differentiators include its robust support for Node.js `cluster` module aggregation, providing sensible defaults for common metrics, and a rich set of built-in 'default metrics' for runtime performance and resource usage. It ships with TypeScript types, enabling strong typing for metric definitions and interactions.","language":"javascript","status":"active","last_verified":"Tue Apr 21","install":{"commands":["npm install prom-client"],"cli":null},"imports":["import { Registry } from 'prom-client';","import { collectDefaultMetrics } from 'prom-client';","import { Counter } from 'prom-client';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import express from 'express';\nimport { collectDefaultMetrics, Registry, Counter } from 'prom-client';\n\nconst app = express();\nconst port = process.env.PORT || 3000;\n\n// Create a new registry to register custom metrics\nconst register = new Registry();\n\n// Collect default metrics like CPU, memory, event loop lag, etc.\n// These are registered to the custom 'register' instance.\ncollectDefaultMetrics({\n  register: register,\n  prefix: 'my_app_',\n  labels: { APP_NAME: 'my_service' }\n});\n\n// Create a custom counter metric\nconst httpRequestCounter = new Counter({\n  name: 'my_app_http_requests_total',\n  help: 'Total number of HTTP requests',\n  labelNames: ['method', 'route', 'status'],\n  registers: [register]\n});\n\n// Example route to increment the counter\napp.get('/', (req, res) => {\n  httpRequestCounter.inc({ method: 'GET', route: '/', status: 200 });\n  res.send('Hello World!');\n});\n\n// Expose metrics at the /metrics endpoint\napp.get('/metrics', async (req, res) => {\n  res.set('Content-Type', register.contentType);\n  res.end(await register.metrics());\n});\n\napp.listen(port, () => {\n  console.log(`Server listening at http://localhost:${port}`);\n  console.log(`Metrics available at http://localhost:${port}/metrics`);\n});","lang":"typescript","description":"This quickstart demonstrates how to set up an Express.js server, collect default Node.js metrics, define a custom counter, and expose them on a /metrics endpoint, all using a dedicated Prometheus registry.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}