New:Microsoft Teams Notifications Are Now Available in Socket.Learn more →
Get Started

mem-pressure

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mem-pressure

Monitor Node.js memory usage and emit events when thresholds are exceeded

latest
Source
npmnpm
Version
1.0.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

mem-pressure

Monitor Node.js memory usage and emit events when thresholds are exceeded

Install

npm install mem-pressure

Usage

import MemoryMonitor, {getMemorySnapshot} from 'mem-pressure';

const monitor = new MemoryMonitor({threshold: 0.9, interval: 10_000});

monitor.addEventListener('pressure', event => {
	console.log('Memory pressure detected!');
	console.log(`Heap usage: ${(event.detail.heapUsedRatio * 100).toFixed(1)}%`);
});

monitor.start();

// Get a one-off snapshot
const snapshot = getMemorySnapshot();
console.log(snapshot.heapUsedRatio);

// Stop monitoring
monitor.stop();

API

MemoryMonitor(options?)

Creates a new memory monitor instance. Extends EventTarget.

options

Type: object

threshold

Type: number
Default: 0.85

Heap usage ratio (0-1) at which to emit 'pressure' events.

interval

Type: number
Default: 5000

Polling interval in milliseconds.

Events

'pressure'

Emitted when heapUsed / heapTotal exceeds the threshold. The listener receives a CustomEvent with detail set to a MemorySnapshot object.

.start()

Start monitoring memory usage. Returns this for chaining.

.stop()

Stop monitoring memory usage. Returns this for chaining.

[Symbol.dispose]()

Calls .stop(). Enables use with the using declaration.

getMemorySnapshot()

Returns a MemorySnapshot object with the following properties:

  • rss — Resident Set Size in bytes
  • heapTotal — Total size of the allocated heap in bytes
  • heapUsed — Actual memory used during execution in bytes
  • external — Memory used by C++ objects bound to JavaScript objects in bytes
  • arrayBuffers — Memory allocated for ArrayBuffer and SharedArrayBuffer in bytes
  • heapUsedRatio — Ratio of heapUsed to heapTotal (0-1)
  • v8 - Node.js V8 API
  • process.memoryUsage - Node.js memory usage API

License

MIT

Keywords

memory

FAQs

Package last updated on 16 Feb 2026

Related posts