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

profiler-heapdump

v3.1.1

Published

Provides ability to capture a profile and heapdump via a curl or wget commands which downloads the results to the local filesystem.

Readme

profile-heapdump

Provides ability to capture a profile and heapdump via a curl or wget commands which downloads the results to the local filesystem.

Profile

Profile via a curl or wget command which downloads the results to the local filesystem. Configurable sampling and profile duration.

For compatibility, utilizes the node.js integrated inspector API.

Use when a profile is needed in a remote environment and the server is accessible, but not the filesystem. In kubernetes, if profiling writes to a local ephemeral filesystem and the pod or minion crashes, the file is lost.

This library efficiently streams the results back to prevent dominating the event thread which would unnecessarily increase latency of other requests.

Uses either a provided express app or creates a new express app. The new express app provides auth and exponential rate limiting on auth failures. If using a provided express app, BYO auth and rate limiting. The auth middleware which includes rate limiting is exposed for use with provided express apps via the getAuthMiddleware function.

Parameters:

  • durationSec default 10 seconds
  • sampleRateUs default 1000 us or 1 ms

The longer duration or the higher the sample rate, the more memory required and larger the file.

# default test config is basic auth, this will fail with 401

curl --compressed \
-G http://localhost:6660/debug/profile \
-d durationSec=10 \
-d sampleRateUs=1000 \
-o testProfile1.cpuprofile \
-H "Authorization: Bearer changeme"

OR

curl --compressed \
'http://localhost:6660/debug/profile?durationSec=10&sampleRateUs=1000' \
-o testProfile1.cpuprofile \
-u "change:me"

OR

wget --http-user=change --http-password=me --auth-no-challenge \
'http://localhost:6660/debug/profile?durationSec=10&sampleRateUs=1000' \
-O testProfile1.cpuprofile

Curl basic auth

-u "username:password"

Curl bearer auth

-H "Authorization: Bearer <TOKEN>"

wget basic auth

Using '--auth-no-challenge' reduces an extra round-trip to challenge wget.

--user <user> --password <pass> --auth-no-challenge

wget bearer auth

--header="Authorization: Bearer <TOKEN>"

Opening Profile

  • Open chrome inspector chrome://inspect/#devices
  • Click on Open dedicated DevTools for Node
  • Click on Profiler tab
  • Click Load button at bottom or right click on left nav bar and click on Load
  • Select a file with the extension .cpuprofile which contains JSON
  • Click on the file in the left nav bar under CPU PROFILES

Interpreting Profile

  • Self time: How long it took to complete the current invocation of the function, including only the statements in the function itself, not including any functions that it called.
  • Total time: The time it took to complete the current invocation of this function and any functions that it called.
  • Aggregated self time: Aggregate time for all invocations of the function across the recording, not including functions called by this function.
  • Aggregated total time: Aggregate total time for all invocations of the function, including functions called by this function.

Configuration

Init with existing express

import { init, shutdown } from 'profiler-heapdump'

const app = express()
// BYO auth or use built-in auth with rate-limiting

app.use('/debug', init({
  server: {
    isExistingExpressApp: true,
  },
}))

// start the server
// const server = app.listen ...

Init create new express

import { init, shutdown } from 'profiler-heapdump'

init({
  authentication: {
    bearer: 'changeme',
  },
})

// on sigterm gracefully shutsdown the server by calling shutdown

Options

Below are the defaults. Be sure to set the authentication.

const defaultOptions = {
  server: {
    isExistingExpressApp: false,
    newExpresRoutePrefix: undefined,
    bind: {
      host: '127.0.0.1',
      port: 6660,
    },
    authentication: {
      basic: {
        username: undefined,
        password: undefined,
      },
      bearerToken: undefined,
    },
  },
  cpu: {
    profiling: {
      durationMs: 10000,
      sampleRateUs: 1000, // 1 ms
    },
  },
}

Heap Dump

Get heap dump via a curl or wget command which downloads the results to the local filesystem.

# default test config is basic auth, this will fail with 401

curl --compressed \
-G http://localhost:6660/debug/heapdump \
-o testHeap.heapsnapshot \
-H "Authorization: Bearer changeme"

OR

curl --compressed \
'http://localhost:6660/debug/heapdump' \
-o testHeap.heapsnapshot \
-u "change:me"

OR

wget --http-user=change --http-password=me --auth-no-challenge \
'http://localhost:6660/debug/heapdump' \
-O testHeap.heapsnapshot