# NodeJS - JavaScript heap out of memory

### Problem <a href="#problem" id="problem"></a>

When running the SeaLights NodeJS agent, the error "`JavaScript heap out of memory`" is encountered.

### Solution <a href="#solution" id="solution"></a>

By default node is limited in the amount of memory it is allocated, and sometimes the SeaLights node agent requires more memory that what was allocated.\
More memory can be allocated by using the `max-old-space-size` flag.

The flag can be passed either by **using the NODE\_OPTION environment variable**, for example:

{% tabs %}
{% tab title="Linux" %}
{% code overflow="wrap" lineNumbers="true" %}

```sh
export NODE_OPTIONS=--max-old-space-size=4096
```

{% endcode %}
{% endtab %}

{% tab title="Windows" %}
{% code overflow="wrap" lineNumbers="true" %}

```powershell
set NODE_OPTIONS=--max-old-space-size=4096
```

{% endcode %}
{% endtab %}
{% endtabs %}

Alternatively, it can be **passed directly to node process** running the SeaLights agent, for example:

{% code overflow="wrap" lineNumbers="true" %}

```
node --max-old-space-size=4096 ./node_modules/.bin/slnodejs scan ...
```

{% endcode %}

{% hint style="info" %}
To show the current max heap size being used by Node.js *at runtime* (after accounting for `NODE_OPTIONS` or any CLI overrides), you can execute:

```
node -p "v8.getHeapStatistics().heap_size_limit / 1024 / 1024 + ' MB'"
```

{% endhint %}

### Related articles <a href="#related-articles" id="related-articles"></a>

* [running-tests](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/go-agent/go-agent-v1/running-tests "mention") (Go)
* [setting-up-a-windows-service](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/capturing-coverage-from-the-application/ms-windows-specific-configurations/setting-up-a-windows-service "mention") (.Net Core)
* [setting-up-iis-listener](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/capturing-coverage-from-the-application/ms-windows-specific-configurations/setting-up-iis-listener "mention") (.Net Core)
* [cloud-foundry-integration](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/python-agent/capturing-coverage-from-runtime-application/cloud-foundry-integration "mention") (Python)
* [pivotal-cloud-foundry-pcf-support](https://docs.sealights.io/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/pivotal-cloud-foundry-pcf-support "mention") (Java)
