Here’s an example showing how to use the [Heap Profiler][]:

    1. const inspector = require('inspector');
    2. const fs = require('fs');
    3. const session = new inspector.Session();
    4. const fd = fs.openSync('profile.heapsnapshot', 'w');
    5. session.connect();
    6. session.on('HeapProfiler.addHeapSnapshotChunk', (m) => {
    7. fs.writeSync(fd, m.params.chunk);
    8. });
    9. session.post('HeapProfiler.takeHeapSnapshot', null, (err, r) => {
    10. console.log('HeapProfiler.takeHeapSnapshot done:', err, r);
    11. session.disconnect();
    12. fs.closeSync(fd);
    13. });