Cheat Sheet - Node.js

Optimizing Node.js memory usage

Chances are that you are experiencing issues like this:
https://stackoverflow.com/questions/55757966/very-slow-ng-build-prod-in-docker

# Note: the parameter does not use underscores!
NODE_OPTIONS=--max-old-space-size=4096
NODE_OPTIONS=--max-old-space-size=3584

For Cloud Foundry users

Low Memory Environments
When running node apps, you might notice that instances are occasionally restarted due to memory constraints. Node does not know how much memory it is allowed to use, and thus sometimes allows the garbage collector to wait past the allowed amount of memory. To resolve this issue, set the OPTIMIZE_MEMORY environment variable to true (requires node v6.12.0 or greater). This sets max_old_space_size based on the available memory in the instance.

$ cf set-env my-app OPTIMIZE_MEMORY true

https://docs.cloudfoundry.org/buildpacks/node/node-tips.html