process.memoryUsage()
A Node.js function that reports the process's memory use in bytes: rss, heapTotal, heapUsed, external and arrayBuffers.
In more detail
heapUsed is memory taken by live JavaScript objects, heapTotal is what V8 has reserved for its heap, and external counts native memory such as Buffer contents. Logging it at intervals is a quick way to spot a memory leak.
Related terms
- resident set size — The amount of physical memory (RAM) a process is actually occupying right now, including its code, stacks, heap and buffers.
- heap — The area of memory where a program stores objects whose size or lifetime is not known in advance, typically reclaimed by a garbage collector.
- external memory — Memory that belongs to JavaScript objects but lives outside the V8 heap, such as the bytes inside Buffers and ArrayBuffers.
- memory leak — Memory that a program keeps holding although it no longer needs it, so usage grows until the program slows down or crashes.
Taught in
- Node.js Process Architecture: Memory & Heap Spaces — Node.js Internals & Backend Services
- Backpressure Engineering: Handling Mismatched I/O — Node.js Internals & Backend Services