Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set memory limit to NodeJS running with forever

I'm running my Node JS process through forever as below:

sudo forever start -o out.log -e error.log myServer.js

I want to change the memory limit of my NodeJs server as I do like below when I'm running it purely with node.

node --max-old-space-size=512 myServer.js

How I can do the same when I'm running it with forever? Is there some way like 'forever start --max-old-space-size=512'

like image 336
kelumch Avatar asked Aug 08 '16 08:08

kelumch


People also ask

How do I increase Node JS memory limit?

If you want to increase the max memory for Node you can use --max_old_space_size option. You should set this with NODE_OPTIONS environment variable.

How do I run Node js server permanently?

js application locally after closing the terminal or Application, to run the nodeJS application permanently. We use NPM modules such as forever or PM2 to ensure that a given script runs continuously. NPM is a Default Package manager for Node.

How much memory can nodeJS use?

By default, Node. js (up to 11. x ) uses a maximum heap size of 700MB and 1400MB on 32-bit and 64-bit platforms, respectively.

What is Node default memory limit?

Node has a default max memory usage of less than 2GB on some 64bit systems (depending on the Node runtime version). This can cause unexpected memory issues when running on CircleCI. It's possible to adjust the max memory ceiling using a command-line flag passed into Node: --max-old-space-size=<memory in MB>


1 Answers

You can pass node options by changing the command (which defaults to "node").

So for example:

sudo forever start -c "node --max_old_space_size=512" -o out.log -e error.log myServer.js
like image 52
Paul Avatar answered Sep 23 '22 09:09

Paul