# 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](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/go-agent/go-agent-v1/running-tests.md) (Go)
* [Setting up a windows service](/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.md) (.Net Core)
* [Setting up IIS Listener](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/.net-core-agent/capturing-coverage-from-the-application/ms-windows-specific-configurations/setting-up-iis-listener.md) (.Net Core)
* [Cloud Foundry Integration](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/python-agent/capturing-coverage-from-runtime-application/cloud-foundry-integration.md) (Python)
* [Pivotal Cloud Foundry (PCF) Support](/knowledgebase/setup-and-configuration/sealights-agents-and-plugins/java-agent/pivotal-cloud-foundry-pcf-support.md) (Java)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sealights.io/knowledgebase/setup-and-configuration/troubleshooting-faq/node-javascript/nodejs-javascript-heap-out-of-memory.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
