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

mtrics-express

v1.4.0

Published

With this project you can connect your express application with influxdb and render a dashboard in grafana.

Readme

Express metrics

With this project you can connect your express application with influxdb and render a dashboard in grafana.

By default it gather a classic group of parameters, like request duration, code, bytes, url, domain and referer. It also allow you to create custom functions to gather other metrics.

You can install this with npm i mtrics-express and see in npm

Basic use

You can easily add this module as a middleware of your express app, without any config, only naming your metric for example with the name of your project. You can go to the examples/basic folder to see an example.

Advanced use

If you need more funcionality, you can go to examples/custom-config to see an example of an advanced use of the library to extends the metrics gathered by the middleware. Yo need to specify in your config file the schema of the measurement and your custom transform function needs to receive as params the request and the response, and needs to return an array with [tags, fields] as objects.

Example of custom config file

module.exports = {
  measurement: {
    name: 'express'
  },
  schema: {
    userEmail: 'string'
  }
};

Here we can see that the name of the measurement is express and the extended schema accemts a new field named userEmail and his type is string it allows more types like:

  • float (f)
  • boolean (b)
  • integer (i)
  • string (s)
const influx = require('../../src')(config, (req, res) => {
  return [{}, { userEmail: req.user }];
});

const app = express();
app.use(influx);

Here we can see how to configure our express application, for example passing the previous config file and adding a transform function that returns an array with an empty object as extended tags and an object with our new metric in the fields object.

If you want, can apply a blacklist in your config file, to allow the middleware to do not track some user-agents.

module.exports = {
  measurement: {
    name: 'express'
  },
  schema: {
    userEmail: 'string'
  },
  blackList: ['your-custom-user-agent']
};

Requeriments

This library is thought to be used with an influxDb database and a grafana dashboard to paint the metrics is included in the project in the dashboard.json file, ready to be imported.

Dependencies

This library uses:

  • geoip-lite 1.4.7: To geolocalize the ip directions and be able to draw on a map.
  • influxdb-nodejs 3.1.0: Connectivity layer with influx
  • on-headers 1.0.2: Easily manage the response just before we send it.
  • lodash 4.17.21: Utility library

Contributions

This project exists thanks to the following people: