node js check ram usage 1

node js check ram usage

const arr = [1, 2, 3, 4, 5, 6, 9, 7, 8, 9, 10];
arr.reverse();
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`);

Here is what the above code is Doing:
1. We’re creating an array with 10 elements.
2. We’re reversing the array.
3. We’re calculating the memory used by the script.

The output of the above script is:
The script uses approximately 0.07 MB

Now, let’s add one more line to the above script:

Similar Posts