Utility to manage Node.js memory
npm install super-mem
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.
hrOnlyboolean? Human readable format only, defaultfalse
{
"rss": 42360832,
"heapTotal": 35254272,
"heapUsed": 16044848,
"external": 108125,
"rssHR": "42.4 MB",
"heapTotalHR": "35.3 MB",
"heapUsedHR": "16 MB",
"externalHR": "108 kB"
}Returns an object describing the OS memory measured in bytes and human readable format. Note that it uses base-10.
hrOnlyboolean? Human readable format only, defaultfalse
{
"totalMem": 17073917952,
"freeMem": 11155980288,
"totalMemHR": "17.1 GB",
"freeMemHR": "11.2 GB"
}Returns the size of the 'inputObject', measured in bytes and human readable format. Note that it uses base-10.
inputObjectObject Object to measure the sizehrOnlyboolean? Human readable format only, defaultfalse
{
"size": 20488,
"sizeHR": "20.5 kB"
}Print the memory status on console
decoratorstring? Optional string to create header and footer, default"-"
-------------------- Memory Status --------------------
β’ Process memory usage:
rss = 45.7 MB
heapTotal = 35.8 MB
heapUsed = 18.7 MB
β’ OS memory:
totalmem = 17.1 GB
freemem = 11.1 GB
-------------------------------------------------------Monitors the heap memory and if the heap used exceeds the limitPerc, it notifies this to the handling functions
limitPercnumber Limit exceeded which the handling function is calledintervalnumber? Optional, time interval between memory reading, default10000 ms
const superMem = require('super-mem');
const heapObserver = new superMem.HeapObserver(80, 5000);
heapObserver.addHandler(function (mem, percentage) {
console.log('HeapObserver MEM: ' + JSON.stringify(mem, null, 2));
console.log('HeapObserver PERC: ' + parseInt(percentage) + ' %');
});
heapObserver.start();