Super Mem
Utility to manage Node.js memory
Install
npm install super-mem
API
Table of Contents
memoryUsage
Returns an object describing the memory usage of the Node.js process measured in bytes and human readable format. Note that it uses base-10.
Parameters
hrOnly
boolean? Human readable format only, defaultfalse
Examples
"rss": 42360832 "heapTotal": 35254272 "heapUsed": 16044848 "external": 108125 "rssHR": "42.4 MB" "heapTotalHR": "35.3 MB" "heapUsedHR": "16 MB" "externalHR": "108 kB"
osMemory
Returns an object describing the OS memory measured in bytes and human readable format. Note that it uses base-10.
Parameters
hrOnly
boolean? Human readable format only, defaultfalse
Examples
"totalMem": 17073917952 "freeMem": 11155980288 "totalMemHR": "17.1 GB" "freeMemHR": "11.2 GB"
sizeOf
Returns the size of the 'inputObject', measured in bytes and human readable format. Note that it uses base-10.
Parameters
inputObject
Object Object to measure the sizehrOnly
boolean? Human readable format only, defaultfalse
Examples
"size": 20488 "sizeHR": "20.5 kB"
printMemoryStatus
Print the memory status on console
Parameters
decorator
string? Optional string to create header and footer, default"-"
Examples
-------------------- Memory Status -------------------- • Process memory usage: rss = 457 MB heapTotal = 358 MB heapUsed = 187 MB • OS memory: totalmem = 171 GB freemem = 111 GB-------------------------------------------------------
HeapObserver
Monitors the heap memory and if the heap used exceeds the limitPerc
, it notifies this to the handling functions
Parameters
limitPerc
number Limit exceeded which the handling function is calledinterval
number? Optional, time interval between memory reading, default10000 ms
Examples
const superMem = ;const heapObserver = 80 5000;heapObserver;heapObserverstart;