mgffdeg
mgffdeg

Reputation: 21

Increase memory limit in nodejs

I am trying to increase memory limit in node, so I added an environment variable

here is how I did it

it does not work not sure why I also tried it with capital letters here is how I test it

 const maxHeapSz = require('v8').getHeapStatistics().heap_size_limit;
 const maxHeapSz_GB = (maxHeapSz / 1024 ** 3).toFixed(1);
 console.log(`${maxHeapSz_GB}GB`);

I keep gettin 2GB, I'm trying to get 8GB

I appreciate any help

Upvotes: 2

Views: 2617

Answers (2)

Eduard
Eduard

Reputation: 1374

The actual memory that is consumed by the application (in the form of objects in the JavaScript heap) is represented by heapUsed field in process.memoryUsage() API.

You can check for more information here. This article also shows methods to increase the maximum heap size.

Upvotes: 0

Viettel Solutions
Viettel Solutions

Reputation: 1489

You can use

node --max-old-space-size=8192 app.js

It's work for me!

Result:

node --max-old-space-size=8192 test.js 
8.0GB

Upvotes: 1

Related Questions