title: Monitor maximum memory consumption in Node.js process
body: <p>I'm looking for a cross-platform way to reliably monitor maximum memory  consumption in Node.js process, regardless of whether there are leaks or not. </p>
  
  <p>The processes in my case are both real applications and synthetic tests.</p>
  
  <p>I would expect it to work like</p>
  
  <pre><code>process.on('exit', () =&gt; {
    console.log('Max memory consumption: ' + ...);
  });
  </code></pre>
  
  <p>It was possible to trace memory consumption somehow with <code>node --trace_gc ...</code>, but this resulted in output that is hard to read (and probably hard to analyze programmatically). Also, GC didn't occur when a script ended too fast, even if RAM usage was substantial.</p>
  
  <p>From what I have seen on the subject, usually <code>memwatch</code> is suggested for that, like:</p>
  
  <pre><code>require('memwatch-next').on('stats', stats =&gt; {
    console.log('Max memory consumption: ' + stats.max);
  });
  </code></pre>
  
  <p>But in my case it triggered only when GC already happened or didn't trigger at all, so it was useless for determining RAM consumption peaks.</p>
  
  <p>I would prefer to avoid GUI tools like <code>node-inspector</code> if possible.</p>
  
  <p>Can this maximum memory consumption be reliably retrieved as a number from the application itself or CLI alone, cross-platform? </p>