3 ms·
If you want to reduce memory consumption by your node.js server, minify it (e.g. via esbuild in node.js mode) and don't use inline source maps (if you want to k
by sod 4y ago
If you want to reduce memory consumption by your node.js server, minify it (e.g. via esbuild in node.js mode) and don't use inline source maps (if you want to keep source maps, use .map files).
node.js keeps all source code as string in memory. So unminified code can bloat your runtime by a lot if you require a couple of external libraries. If you bundle the libraries as well, you don't even need to copy node_modules anymore, which can also save time in deploying a change.
This small change can cut your memory requirement in half.
Of course I wish node.js just had an option to free the memory of the source code garbage, but as of version 18.9.1 there is none.