Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting Node.js using forever with --nouse-idle-notification and other flags

Tags:

node.js

Previously, I started my production node app via:

NODE_ENV=production forever start index.js

However, per the suggestions in this question, I'd like to start node with --nouse-idle-notification. I also found this article about setting --max-old-space-size, etc. Unfortunately, nobody I ask can seem to figure out how to tell if the flag is actually accepted by node, so I'm not sure how to tell if my forever syntax is correct.

Furthermore, I can't get forever to accept both arguments...

Eg, if I use this

NODE_ENV=production forever start --max-old-space-size=8192 --nouse-idle-notification index.js

I get the "forever usage information", as if I had tried to start forever without passing a .js file to run (eg, just typing "forever"). If I put the flags before the "start" command, it seems to start, but again I'm not sure how to tell if the flags were accepted...

Can someone please help me with the correct syntax?

like image 760
Zane Claes Avatar asked Oct 15 '12 18:10

Zane Claes


2 Answers

You need to pass -c parameter:

forever start -c "node --max-old-space-size=8192 --nouse-idle-notification" index.js

If you list the processes, you'll see the flags are honoured.

forever list
like image 79
Deniz Ozger Avatar answered Nov 14 '22 22:11

Deniz Ozger


Unless you really love forever for some other reason, try mon.

It's super easy to pass flags because you can specify the exact command:

mon "node --max-old-space-size=8192 --nouse-idle-notification --expose-gc server.js" -d

It monitors only a node process. If you want to monitor a group of processes like forever does, install mongroup, its a bash script that manages mon.

This will save you some RAM, specially if you're monitoring a lot of node processes (I think forever launches one additional node process for every process you want to monitor).

quick tip: last time I checked, TJ Holowaychuk's branch of mon was not working well under linux (I guess he only tested on Mac), but this one works and its the one I'm using right now. EDIT: Actually 2 days ago the issue was closed and the main branch should now be working.

like image 23
João Pinto Jerónimo Avatar answered Nov 14 '22 23:11

João Pinto Jerónimo