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

memory-usage

v1.2.1

Published

A readable stream that samples and emits memory usage over time

Downloads

10,009

Readme

memory-usage

A readable stream that samples and emits memory usage over time.

You can for instance use the output to graph your memory usage.

Can also be used from the command line to chart the memory usage of a Node.js app directly in a web browser.

Build status js-standard-style

Installation

For CLI usage:

npm install memory-usage -g

For programmatic usage:

npm install memory-usage --save

CLI Usage Example

Use the memory-usage command instead of the node command:

memory-usage server.js

The memory usage of server.js will now be displayed live in your default web browser:

chart

Programmatic Usage Example

Sample memory usage every 2 seconds and write it to a CSV file:

var fs = require('fs')
var csvWriter = require('csv-write-stream')
var memoryUsage = require('memory-usage')

memoryUsage(2000)
  .pipe(csvWriter())
  .pipe(fs.createWriteStream('memory.csv'))

Note that you application of course have to do some actual work. If you just run the example above as is, the node process will simply exit after creating an empty file.

If you want to chart the memory usage, I recommend combining this module with chart-csv.

API

stream = memoryUsage([freq|options])

Will start sampling memory usage every freq milliseconds (defaults to 5000) as soon as the stream is flowing.

The optional options object expects the following properties:

  • freq - The sampling frequency in milliseconds (defaults to 5000)
  • ts - A boolean specifying if a timestamp should be outputtet along with the memory samples (defaults to false)
  • gc - A boolean specifying if garbage collection should be profiled and logged along with the memory samples (defaults to false)

The stream emits samples in the form of JavaScript objects:

{
  rss: 4935680,       // Resident set size: Memory assigned to the process in bytes
  heapTotal: 1826816, // V8 heap memory allocated in bytes
  heapUsed: 650472,   // V8 heap memory used in bytes
  ts: 1479179912921,  // UNIX epoch timestamp for sample in milliseconds (only present if `optsions.ts` is `true`)
  gc: null            // Indicates if sample was taken after a garbage collection run (only present if `options.gc` is `true`)
}

If the gc property is null, it means that the sample wasn't taken after a garbage collection run. If the value is a string, it will indicate the type of garbage collection run. Currently, the values can be either Scavenge or MarkSweepCompact.

Note that samples indicating a garbage collection run might be a few hundred milliseconds delayed. This means that you might see a regular timed sample appear prior in the stream with reduced memory usage, even though there's no official indication of a garbage collection run yet.

License

MIT