title: How to limit node application memory size, and how to verify current memory usage and capacity?
body: <p>I want to customize node application memory size, also I want to add some middleware to record realtime application memory usage and capacity. </p>
  
  <p>I know memory limit can be raised by setting --max-old-space-size to a maximum of ~1gb (32-bit) and ~1.7gb (64-bit)</p>
  
  <p>Example:</p>
  
  <pre><code>node --max-old-space-size=1024 app.js
  </code></pre>
  
  <p>But when I use v8, how to verify memory capacity and usage?</p>
  
  <p>Update:</p>
  
  <p>I have used another approach to raise memory for app with v8.</p>
  
  <pre><code>const v8 = require('v8');
  v8.setFlagsFromString('--max_old_space_size=2048');
  </code></pre>
  
  <p>This is log for HeapSpaceStatistics</p>
  
  ########## v8.getHeapSpaceStatistics() ################
  
  <pre><code>[
      {
          "space_name": "new_space",
          "space_size": 1048576,
          "space_used_size": 781704,
          "space_available_size": 249464,
          "physical_space_size": 798416
      },
      {
          "space_name": "old_space",
          "space_size": 18874368,
          "space_used_size": 16844024,
          "space_available_size": 270840,
          "physical_space_size": 18772464
      },
      {
          "space_name": "code_space",
          "space_size": 4718592,
          "space_used_size": 4344800,
          "space_available_size": 95424,
          "physical_space_size": 4586176
      },
      {
          "space_name": "map_space",
          "space_size": 1572864,
          "space_used_size": 962104,
          "space_available_size": 584648,
          "physical_space_size": 1187888
      },
      {
          "space_name": "large_object_space",
          "space_size": 1626112,
          "space_used_size": 1603664,
          "space_available_size": 1471614464,
          "physical_space_size": 1626112
      }
  ]
  </code></pre>
  
  <p>I have set memory limit for 2GB, base on log, how to verify that?</p>