Complete the code to import the module used to take heap snapshots in Node.js.
const heapdump = require('[1]');
The heapdump module is used to take heap snapshots in Node.js for memory leak analysis.
Complete the code to trigger a heap snapshot save with a filename.
heapdump.writeSnapshot('[1]', (err, filename) => { if (err) console.error(err); else console.log('Snapshot saved to', filename); });
The filename for the heap snapshot is usually given with a .heapsnapshot extension, such as 'memory.heapsnapshot'.
Fix the error in the code to correctly listen for a signal to trigger a heap snapshot.
process.on('[1]', () => { heapdump.writeSnapshot(); });
SIGUSR2 is commonly used to trigger heap snapshots in Node.js without stopping the process.
Fill both blanks to create a heap snapshot filename with a timestamp.
const filename = `heap-[1]-[2].heapsnapshot`;
new Date() directly in filename without formatting.Math.random() which is not descriptive.Using Date.now() gives a timestamp, and process.pid adds the process ID to the filename for uniqueness.
Fill all three blanks to write a heap snapshot and log the filename with error handling.
heapdump.writeSnapshot([1], ([2], [3]) => { if ([2]) console.error([2]); else console.log('Snapshot saved:', [3]); });
The first blank is the filename string, the second is the error parameter, and the third is the filename parameter in the callback.