/** * The memory usage logger for a Node.js process * * Resident Set Size (RSS) is the amount of space occupied in the main memory * device for the process, which includes the heap, code segment and stack. * Variables are stored in the stack and the actual JavaScript code resides in the code segment. * * The heap is where objects, strings, and closures are stored. * * @see https://nodejs.org/api/process.html#process_process_memoryusage */ setInterval(function () { const mem = process.memoryUsage(); function fmt(v) { return (v / (1024 * 1024)).toFixed(3); } console.error( 'RSS = ' + fmt(mem.rss) + ', ' + 'Heap Total = ' + fmt(mem.heapTotal) + ', ' + 'Heap Used = ' + fmt(mem.heapUsed) ); }, 5000);