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

memory-leak-diagnose

v0.0.5

Published

πŸ” A lightweight CLI tool to help developers quickly identify abnormal memory usage in Node.js applications. Supports both self-monitoring and child process monitoring with real-time alerts, JSON output, and heap snapshots.

Downloads

10

Readme

memory-leak-diagnose

Logo

Clarity. Fast. βœ… Monitor Memory + Disk + CPU βœ… JSON output for CI/CD βœ… Works with child processes βœ… Lightweight (~200KB)

npm version npm downloads License: MIT Node.js CI CD Code Style npm install

A fast, lightweight CLI to monitor Node.js memory and disk usage in real time. Track leaks, set alerts, and integrate with CI β€” all with zero setup.

Perfect for Node.js devs, CI/CD, Electron apps, and long-running scripts.

✨ Why This Tool?

Unlike heavy profilers or outdated packages, this tool is fast, zero-dependency (except pidusage), and CI-ready. Get instant memory and disk insights without the complexity. Monitor both system resources in one lightweight tool.

βœ… Again, Why memory-leak-diagnose? Tired of bloated profilers or guessing why your app eats RAM? memory-leak-diagnose gives you real-time Memory, Disk, and CPU stats in a tiny CLI tool. Perfect for:

Debugging Node.js memory leaks

Electron app monitoring

CI/CD resource checks

Long-running scripts

πŸš€ Key Features

  • βœ… CPU usage monitoring (NEW)
  • βœ… Monitor memory live with alerts & thresholds
  • βœ… Disk usage monitoring across all platforms (Windows, macOS, Linux)
  • βœ… Child process support (node app.js, npm run dev)
  • βœ… CI-friendly with JSON output & logs

πŸ“¦ Quick Install

npm install -g memory-leak-diagnose

🎯 Quick Start

# Monitor your app (includes memory + disk)
memory-leak-diagnose node app.js

# Monitor with alerts
memory-leak-diagnose --threshold 200 --interval 500 npm run dev

# Monitor disk usage during large operations
memory-leak-diagnose --interval 2000 npm run build

πŸ“– Usage Examples

Self-Monitoring (Default)

memory-leak-diagnose

Monitors the tool's own memory usage every second with a 100MB threshold.

Child Process Monitoring

# Monitor a Node.js app
memory-leak-diagnose node index.js

# Monitor npm scripts
memory-leak-diagnose npm run dev
memory-leak-diagnose npm start

# Monitor other processes
memory-leak-diagnose python script.py
memory-leak-diagnose java -jar app.jar

# Monitor existing process by PID
memory-leak-diagnose --pid 12345

# Show live chart
memory-leak-diagnose --chart --interval 500 node server.js

# Monitor with disk usage (included by default)
memory-leak-diagnose --interval 2000 npm run build

Advanced Configuration

# Custom interval and threshold
memory-leak-diagnose --interval 500 --threshold 200 node server.js

# JSON output for CI/CD
memory-leak-diagnose --json --threshold 300 npm test

# With logging
memory-leak-diagnose --log-file memory.log --interval 2000 node app.js

# Capture heap snapshot
memory-leak-diagnose --capture-snapshot --label "before-test" node test.js

Package.json Integration

{
  "scripts": {
    "dev": "memory-leak-diagnose npm run dev-server",
    "test:mem": "memory-leak-diagnose --json --threshold 200 npm test",
    "build:mem": "memory-leak-diagnose --log-file build-memory.log npm run build",
    "monitor": "memory-leak-diagnose --interval 1000 --threshold 150 npm start",
    "build:watch": "memory-leak-diagnose --interval 2000 --json npm run build"
  }
}

🎯 Real-World Use Cases

| Use Case | Command | Description | |----------|---------|-------------| | CI Memory Regression | memory-leak-diagnose --json --threshold 300 npm test | Alert if memory exceeds 300MB after commits | | Development Server | memory-leak-diagnose --threshold 150 npm run dev | Monitor memory during development | | Electron Apps | memory-leak-diagnose --log-file electron.log npm run electron | Track memory during window lifecycle | | Long-running Scripts | memory-leak-diagnose --threshold 500 --interval 10000 node worker.js | Detect gradual memory leaks | | Library Debugging | memory-leak-diagnose --capture-snapshot --label "before" node test.js | Compare before/after memory usage | | Existing Process | memory-leak-diagnose --pid 12345 | Monitor already running process | | Disk Space Monitoring | memory-leak-diagnose --json --interval 5000 npm run build | Track disk usage during large builds | | System Health Check | memory-leak-diagnose --chart --interval 1000 | Monitor both memory and disk in real-time |

πŸ“‹ Command Line Options

| Option | Short | Description | Default | |--------|-------|-------------|---------| | --help | -h | Show help message | - | | --interval | -i | Monitoring interval in milliseconds | 1000 | | --threshold | -t | Memory threshold in megabytes | 100 | | --log-file | -l | File path to write logs | - | | --json | -j | Output structured JSON | false | | --capture-snapshot | -s | Capture heap snapshot | false | | --label | - | Label for snapshot | - | | --pid | - | Monitor existing process by PID | - | | --chart | -c | Show ASCII live chart of memory usage | false |

πŸ“Š Output Examples

CLI Example Output

Memory: HeapUsed: 120 MB | RSS: 310 MB
CPU:    8.3%
Disk:   Free: 72 GB / 256 GB (28%)

JSON Output Example

"cpu": {
  "percent": 8.3
}

Standard CLI Output (Self-Monitoring)

Memory Usage: | Process: Self | Heap Used: 45.2 MB | Heap Total: 67.8 MB | RSS: 89.1 MB | Threshold: 100 MB | Breaches: 0 | Status: βœ… Normal | Disk: 721.0 GB free / 913.0 GB (21.0%)

Standard CLI Output (Child Process)

Memory Usage: | Process: PID:12345 | Heap Used: 156.7 MB | Heap Total: 189.2 MB | RSS: 234.5 MB | Threshold: 100 MB | Breaches: 3 | Status: ⚠️  THRESHOLD BREACH | Disk: 721.0 GB free / 913.0 GB (21.0%)

JSON Output

{
  "timestamp": "2024-01-15T10:30:45.123Z",
  "pid": 12345,
  "heapUsed": 47382528,
  "heapTotal": 71065600,
  "rss": 93450240,
  "external": 1234567,
  "arrayBuffers": 0,
  "disk": {
    "total": 980356689920,
    "used": 206137708544,
    "free": 774218981376
  },
  "threshold": 104857600,
  "breachCount": 0,
  "isBreach": false,
  "monitoringChild": true,
  "formatted": {
    "heapUsed": "45.2 MB",
    "heapTotal": "67.8 MB",
    "rss": "89.1 MB",
    "threshold": "100 MB"
  }
}

πŸ”§ Advanced Features

Manual Snapshot Capture

While monitoring is running, capture snapshots using signals:

# In another terminal
kill -USR2 <process_id>

Programmatic Usage

const { MemoryMonitor } = require('memory-leak-diagnose');

const monitor = new MemoryMonitor({
  interval: 1000,
  threshold: 100,
  logFile: 'app-memory.log',
  command: 'node',
  commandArgs: ['server.js']
});

monitor.start();

// Stop monitoring when done
monitor.stop();

πŸ“š Memory Metrics Explained

  • heapUsed: Memory actually used by JavaScript objects
  • heapTotal: Total size of the V8 heap
  • RSS (Resident Set Size): Total memory allocated to the process
  • external: Memory used by C++ objects bound to JavaScript objects
  • arrayBuffers: Memory allocated for ArrayBuffers and SharedArrayBuffers

Note: When monitoring child processes, only RSS memory is available via pidusage. Heap metrics are not available for non-Node.js processes.

πŸ—‚οΈ Disk Monitoring

The tool now includes cross-platform disk usage monitoring:

  • Windows: Uses wmic logicaldisk to get C: drive information
  • macOS/Linux: Uses df -k / to get root filesystem information
  • Automatic fallback: Continues monitoring even if disk check fails
  • JSON integration: Disk data included in structured output

Disk Metrics

  • total: Total disk space in bytes
  • used: Used disk space in bytes
  • free: Available disk space in bytes

πŸ—ΊοΈ Roadmap

Upcoming Features

  • πŸ”„ Advanced disk monitoring: Per-partition monitoring, disk I/O metrics
  • πŸ“Š Network monitoring: Bandwidth usage, connection tracking
  • 🎯 Custom thresholds: Disk space alerts, network bandwidth limits
  • πŸ“ˆ Historical data: Trend analysis, memory/disk usage patterns
  • πŸ”Œ Plugin system: Extensible monitoring capabilities
  • 🌐 Web dashboard: Real-time monitoring interface

Future Enhancements

  • CPU monitoring: Process CPU usage and system load
  • Process tree: Monitor parent-child process relationships
  • Resource profiling: Detailed resource usage breakdown
  • Alert integrations: Slack, Discord, email notifications
  • Export formats: CSV, Prometheus metrics, Grafana dashboards

πŸ› οΈ Installation & Development

Global Installation

npm install -g memory-leak-diagnose

Local Development

git clone https://github.com/thegreatbey/memory-leak-diagnose.git
cd memory-leak-diagnose
npm install
npm link  # Makes the command available globally

Testing

# Test self-monitoring
memory-leak-diagnose

# Test child process monitoring
memory-leak-diagnose node examples/test-child-process.js

# Test with memory leak demo
memory-leak-diagnose node examples/memory-leak-demo.js

πŸ” Troubleshooting

Permission Issues (Windows)

# Run PowerShell as Administrator
Set-ExecutionPolicy RemoteSigned

Child Process Issues

# Check if the command exists
which node
which npm

# Try with explicit path
memory-leak-diagnose /usr/bin/node index.js

Large Log Files

# Use logrotate or similar tools
memory-leak-diagnose --log-file memory-$(date +%Y%m%d).log node app.js

Disk Monitoring Issues

# Check disk permissions (Windows)
# Run as Administrator if needed

# Check disk space manually
df -h /  # Linux/macOS
wmic logicaldisk get size,freespace,caption  # Windows

🀝 Contributing

Pull requests are welcome! We love contributions from the community.

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

For major changes, please open an issue first to discuss what you would like to change.

πŸ“„ License

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

License: MIT

πŸ™ Acknowledgments

  • Built with ❀️ for the Node.js community
  • Inspired by the need for simple, effective memory monitoring tools
  • Uses pidusage for cross-platform process monitoring

πŸ“ž Support

  • Issues: GitHub Issues
  • Discussions: GitHub Discussions
  • Documentation: Check this README and inline code comments
  • Examples: See the examples/ directory for more use cases

Made with ❀️ by the Node.js community

npm npm GitHub stars GitHub forks