node icon indicating copy to clipboard operation
node copied to clipboard

Allow setting `--max-heap-size` in `NODE_OPTIONS`

Open hpedrorodrigues opened this issue 7 months ago • 1 comments

What is the problem this feature will solve?

V8 supports this flag for a while now (see 9306), and it's even documented under --v8-options (see). However, it's not yet supported to set it with NODE_OPTIONS environment variable as it is for some other similar flags like --max-old-space-size (see).

For instance, a process will fail with the following error if we try to do this:

♪ NODE_OPTIONS='--max-heap-size=750' node
node: --max-heap-size= is not allowed in NODE_OPTIONS

What is the feature you are proposing to solve the problem?

Allow setting --max-heap-size in the NODE_OPTIONS environment variable.

What alternatives have you considered?

At the moment, we are forced to set this flag directly in the command line, but this is a bit inconvenient when we have to manage several services and want to dynamically calculate the maximum heap size in containerized environments (e.g., based on the memory limit imposed for a pod in a Kubernetes cluster).

hpedrorodrigues avatar Jun 12 '25 03:06 hpedrorodrigues

Seems unobjectionable. Pull request welcome. See how --max-old-space-size is handled in src/node_options.cc.

bnoordhuis avatar Jun 14 '25 20:06 bnoordhuis

Thanks!


It seems @tannal already opened a pull request. Please let me know if you'll continue working on this or if you need help. 🙏

hpedrorodrigues avatar Jun 18 '25 13:06 hpedrorodrigues

Hi, do we need any tests for this feature/PR? If so, how or where should I add them?

tannal avatar Jun 19 '25 00:06 tannal