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 🙏

© 2026 – Pkg Stats / Ryan Hefner

event-collector

v2.2.0

Published

Allows you to collect meta-data and time different phases in the context of a bigger event such as a request

Readme

Event-Collector

Allows you to collect meta-data and time different phases in the context of one bigger event.

Install

The usual npm install event-collector --save or yarn add event-collector

Creating an EventCollector

With Express

If you are using Express the easiest way to get started is with:

const express = require('express');
const EventCollector = require('event-collector');

const app = express();
app.use(EventCollector.express({some: 'fixed metadata'}, (eventcollector) => {
  console.log(JSON.stringify(eventcollector, null, 2));
}));

This will create a new EventCollector at request.eventcontroller with fixed metadata that will be added to every event. Use this for things like hostnames, versions of your software etc. Use that to add meta-data and time jobs. It will automatically call end add the following metadata:

  • request.hostname
  • request.url
  • request.method
  • response.statusCode
  • response.getHeader('content-type)
  • response.getHeader('content-encoding
  • response.getHeader('cache-control)

The callback passed into the constructor will be called when the request is finished and you can do something useful with all the information you just collected, like logging it, or sending it to 3rd parties like http://honeycomb.io

Without Express

If you are not running Express you can easily create your own EventCollector with const eventcollector = new EventCollector();

Usage

addMeta(meta)

Adds all the keys in meta to the existing meta-data. If one or more keys in meta were already present they will be overwritten.

addError(error)

Adds the error to the errors array and increase errorCount by 1.

startJob(type, meta)

Starts timing a new job with type. If a job already exists with that type a dash + counter is added. Optionally you can pass in meta, which will be added to this particular job. This method saves how many milliseconds into the event we are when the job is started. This is stored as startAtMs. Returns the id of the job.

endJob(id, meta)

Ends the job with the id and stores the duration of this particular job. Optionally you can pass in some meta to be added to the job.

end(meta)

Ends the event and store the totalDuration

Example output

{
  "meta": {
    "hostname": "localhost",
    "url": "/cafes/opal-cafe",
    "method": "GET",
    "rendererVersion": "3.4.2",
    "renderProfile": "linc-profile-generic-react-redux-routerv3",
    "statusCode": 200,
    "contentType": "text/html",
    "contentEncoding": "gzip"
  },
  "time": 1494585065359,
  "jobs": {
    "rendering": {
      "startAtMs": 3.007,
      "durationInMs": 1069.266
    },
    "match": {
      "startAtMs": 3.315,
      "durationInMs": 9.811
    },
    "writeInitialHead": {
      "startAtMs": 13.317,
      "durationInMs": 10.305
    },
    "firstFlush": {
      "startAtMs": 23.147,
      "durationInMs": 0.259
    },
    "firstRenderPass": {
      "startAtMs": 23.819,
      "durationInMs": 44.122
    },
    "rendererInitialSetup": {
      "startAtMs": 23.847,
      "durationInMs": 2.825
    },
    "firstRender": {
      "startAtMs": 26.694,
      "durationInMs": 41.21
    },
    "secondRenderPass": {
      "startAtMs": 1063.935,
      "durationInMs": 6.895
    },
    "sendMainContent": {
      "startAtMs": 1070.966,
      "durationInMs": 1.322
    }
  },
  "errs": [],
  "errorCount": 0,
  "totalDuration": 1074.686
}