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

trackify-resources

v1.0.1

Published

A universal module to monitor resource usage and performance in Node.js and browsers

Readme

trackify-resources

npm version License: MIT


Table of Contents


Introduction

trackify-resources is a universal JavaScript/TypeScript module for measuring resource usage (CPU, memory, execution time) in both Node.js and browser environments. It provides:

  • High-resolution timing using the Performance API or process.hrtime.
  • CPU and memory snapshots in Node.js via pidusage (optional dependency).
  • Page-load metrics in browsers.
  • Simple wrappers to track arbitrary functions or promises.
  • UMD, CommonJS, and ES module builds.

Ideal for profiling, performance monitoring, or building custom dashboards in any JS project.

Features

  • Cross-platform: Works in Node.js, modern browsers, and bundlers.
  • Flexible API: Basic monitor() or rich trackFunction() wrappers.
  • Silent mode: Suppress console output when needed.
  • UMD build: Load via <script> tag and access global ResourceMonitor.
  • TypeScript support: Includes .d.ts declarations for full type safety.

Installation

Install from npm:

npm install trackify-resources
# or
yarn add trackify-resources

Optionally install pidusage for Node.js CPU/memory tracking:

npm install pidusage --save-optional

Basic Usage

import { createResourceMonitor } from 'trackify-resources';

async function example() {
  // Create a monitor (label is optional)
  const monitor = createResourceMonitor('myTask');

  // Simple monitor since instantiation:
  await monitor.monitor();

  // Track an arbitrary async function:
  const { result, stats } = await monitor.trackFunction(
    async () => {
      await new Promise(res => setTimeout(res, 500));
      return 'done';
    },
    'delay500'
  );

  console.log('Function result:', result);
  console.log('Stats:', stats);

  // Retrieve full history:
  console.table(monitor.getHistory());
}

example();

API Reference

createResourceMonitor(label?: string, options?: MonitorOptions): ResourceMonitor

Creates a new ResourceMonitor instance.

  • label (optional): Identifier applied to every measurement.
  • options.silent (boolean): If true, suppresses console logs.

monitor(): Promise<MonitorResult>

Measures resources (time, CPU, memory) from monitor instantiation to call.

Returns a MonitorResult:

interface MonitorResult {
  timestamp: string;   // ISO timestamp
  duration?: number;   // ms
  cpu?: number;        // % (Node only)
  memory?: number;     // MB
  label?: string;      // provided label
}

trackFunction<T>(fn: () => T | Promise<T>, label?: string): Promise<{ result: T; stats: MonitorResult }>

Executes fn, waits for completion, then returns its result along with resource stats.

monitorPageLoad(): Promise<MonitorResult>

Browser-only: waits for the window.load event and measures load time + heap usage.

getHistory(): MonitorResult[]

Returns an array of all collected measurements.

Browser Usage

Import the ES module in modern bundlers:

import { createResourceMonitor } from 'trackify-resources';

const monitor = createResourceMonitor('pageLoad');
monitor.monitorPageLoad().then(stats => {
  console.log('Page loaded in', stats.duration, 'ms');
});

UMD Build

Include via <script> (served from dist/index.umd.js):

<script src="https://unpkg.com/trackify-resources/dist/index.umd.js"></script>
<script>
  const monitor = ResourceMonitor.createResourceMonitor('umdExample');
  monitor.trackFunction(() => {
    // your code
  }, 'myFn').then(({ stats }) => console.log(stats));
</script>

Node.js Usage

const { createResourceMonitor } = require('trackify-resources');

(async () => {
  const monitor = createResourceMonitor('nodeTask');
  await monitor.trackFunction(() => {
    // sync or async code
  }, 'syncTest');
  console.log(monitor.getHistory());
})();

React Example

import React, { useEffect } from 'react';
import { createResourceMonitor } from 'trackify-resources';

export function App() {
  useEffect(() => {
    const monitor = createResourceMonitor('AppMount', { silent: true });
    monitor.trackFunction(() => {
      // trigger a re-render or heavy work
    }, 'first-render').then(({ stats }) => {
      console.log('First render took', stats.duration, 'ms');
    });
  }, []);

  return <div>Your React App</div>;
}

Contributing

Contributions, issues and feature requests are welcome! Feel free to:

  • Open an issue on GitHub
  • Submit a pull request

License

This project is licensed under the MIT License — see the LICENSE file for details.