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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@vestfoldfylke/vestfold-metrics

v1.0.0

Published

Wrapper for prom-client to make it easier to use

Readme

vestfold-metrics

This repository is a wrapper on the prom-client library to provide easier interaction with Prometheus metrics in a Node.js application.

Installation

npm install vestfold-metrics

Usage

All metrics can take optional labels as an array of string in the format ...[name, value]

If a metric is created with a set of labels, all future interactions with that metric must use the same set of labels.

Counter metric

See the prom-client documentation for counter details.

import { count, countInc } from 'vestfold-metrics'

// Create and increment a counter without labels - Will result in a counter named 'my_counter' with the value of 1
count('my_counter', 'This is my counter')

// Increment the same counter again - Will reuse the counter named 'my_counter' and the value is now 2
count('my_counter', 'This is my counter')

// Create and increment a counter with labels - Will result in a counter named 'my_counter_label' with the value of 1 and label 'result' with value 'success'
count('my_counter_label', 'This is my counter with label', ['result', 'success'])

// Increment the same counter again - Will reuse the counter named 'my_counter_label' and the value is now 2 and label 'result' with value 'success'
count('my_counter_label', 'This is my counter with label', ['result', 'success'])



// Create and increment a counter with specific increment value without labels - Will result in a counter named 'my_counter_inc' with the value of 19
countInc('my_counter_inc', 'This is my counter', 19)

// Increment the same counter again with specific increment value - Will reuse the counter named 'my_counter_inc' and the value is now 40
countInc('my_counter_inc', 'This is my counter', 21)

// Create and increment a counter with specific increment value with labels - Will result in a counter named 'my_counter_inc_label' with the value of 19 and label 'result' with value 'success'
countInc('my_counter_inc_label', 'This is my counter with label', 19, ['result', 'success'])

// Increment the same counter again with specific increment value - Will reuse the counter named 'my_counter_inc_label' and the value is now 40 and label 'result' with value 'success'
countInc('my_counter_inc_label', 'This is my counter with label', 21, ['result', 'success'])

Gauge metric

See the prom-client documentation for gauge details.

import { gauge } from 'vestfold-metrics'

// Create and set a gauge without labels - Will result in a gauge named 'my_gauge' with the value of 10
gauge('my_gauge', 'This is my gauge', 10)

// Set the same gauge again - Will reuse the gauge named 'my_gauge' and the value is now 5
gauge('my_gauge', 'This is my gauge', 5)

// Create and set a gauge with labels - Will result in a gauge named 'my_gauge_label' with the value of 15 and label 'result' with value 'success'
gauge('my_gauge_label', 'This is my gauge with label', 15, ['result', 'success'])

// Set the same gauge again - Will reuse the gauge named 'my_gauge_label' and the value is now 8 and label 'result' with value 'success'
gauge('my_gauge_label', 'This is my gauge with label', 8 ['result', 'success'])

Metrics endpoint

Expose your metrics to Prometheus by creating an HTTP endpoint in your Node.js application. This endpoint should return the metrics in the Prometheus exposition format.

Example for Azure Functions:

import { app, HttpRequest, HttpResponseInit, InvocationContext } from '@azure/functions'
import { register } from 'vestfold-metrics'

export async function metrics(_: HttpRequest, __: InvocationContext): Promise<HttpResponseInit> {
  return {
    status: 200,
    headers: { 'Content-Type': register.contentType },
    body: await register.metrics()
  }
}

app.get('metrics', {
  authLevel: 'function',
  handler: metrics
})

Example for Express

import express from 'express'
import { register } from 'vestfold-metrics'

const app = express()

app.get('/metrics', async (_req, res) => {
  res.set('Content-Type', register.contentType)
  res.end(await register.metrics())
})

app.listen(3000, () => {
  console.log('Server listening on port 3000')
})