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

@nicholasdigital/flow-metrics

v0.0.2

Published

A utility library for tracking asynchronous operation flows with lifecycle events, timing, and metadata.

Downloads

5

Readme

@nicholasdigital/flow-metrics

A utility library for tracking asynchronous operation flows with lifecycle events, timing, and metadata.

Installation

npm install @nicholasdigital/flow-metrics

Usage

import FlowMetrics from "@nicholasdigital/flow-metrics";

// Start a flow with a custom logger
await FlowMetrics.begin("user-login", {
  log: { userId: 123 },
  meta: { attempts: 1 },
  timeout: 5000, // 5 second timeout
  logFn: async ({ hash, flowId, event, log, meta, logs }) => {
    console.log(`[${event}] ${hash}:`, log);
  },
});

// Add intermediate logs
await FlowMetrics.log("user-login", { step: "validating" });

// Update metadata
await FlowMetrics.updateMeta("user-login", (meta) => ({
  ...meta,
  validated: true,
}));

// Complete the flow
await FlowMetrics.end("user-login", { log: { success: true } });

// Or mark as failed
await FlowMetrics.fail("user-login", { error: "Invalid credentials" });

API

FlowMetrics.begin(hash, options)

Starts a new flow. Automatically cancels any existing flow with the same hash.

Options:

  • log - Initial log data (default: {})
  • logFn - Async callback for all flow events (default: no-op)
  • meta - Initial metadata object (default: {})
  • matcher - Function to match specific flows when multiple share a hash (default: () => true)
  • timeout - Milliseconds before auto-timeout (default: 10000, set to 0 to disable)

FlowMetrics.log(hash, log, options)

Adds an intermediate log entry and resets the timeout timer.

Options:

  • updater - Function to update metadata: (meta) => newMeta
  • event - Custom event name (default: "LOG")
  • matcher - Function to match specific flow

FlowMetrics.end(hash, options)

Successfully completes a flow.

Options:

  • log - Final log data
  • updater - Function to update metadata
  • matcher - Function to match specific flow

FlowMetrics.fail(hash, log, options)

Marks a flow as failed.

Options:

  • updater - Function to update metadata
  • matcher - Function to match specific flow

FlowMetrics.updateMeta(hash, updater, options)

Updates flow metadata without adding a visible log entry.

Events

The logFn callback receives these events:

| Event | Description | |-------|-------------| | BEGIN | Flow started | | LOG | Intermediate log added | | UPDATE_META | Metadata updated | | END | Flow completed successfully | | FAIL | Flow failed | | CANCEL | Flow cancelled (new flow started with same hash) | | TIMEOUT | Flow timed out |

Callback Data

The logFn receives an object with:

{
  hash,      // Flow identifier
  flowId,    // Unique UUID for this flow instance
  event,     // Event type (BEGIN, LOG, END, etc.)
  log,       // Current log entry data
  meta,      // Current metadata
  logs,      // Array of all log entries in this flow
}

Each log entry includes timing:

  • _createTime - Moment timestamp
  • _createTimeDt - Milliseconds since flow began

Concurrent Flows

Use the matcher option to track multiple concurrent flows with the same hash:

// Start flows for different users
await FlowMetrics.begin("data-fetch", {
  meta: { userId: 1 },
  matcher: (flow) => flow.meta.userId === 1,
});

await FlowMetrics.begin("data-fetch", {
  meta: { userId: 2 },
  matcher: (flow) => flow.meta.userId === 2,
});

// End specific flow
await FlowMetrics.end("data-fetch", {
  matcher: (flow) => flow.meta.userId === 1,
});

License

ISC