6

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?

Community
  • 1
  • 1
Zane Claes
  • 14,732
  • 15
  • 74
  • 131

3 Answers3

15

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
Deniz Ozger
  • 2,565
  • 23
  • 27
1

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.

João Pinto Jerónimo
  • 9,586
  • 15
  • 62
  • 86
-1

You could try:

forever start --max-old-space-size=8192 --nouse-idle-notification -c "NODE_ENV=production node" index.js 
3on
  • 6,291
  • 3
  • 26
  • 22
  • Well, that certainly started the server successfully... but I have no way of knowing if the flags are being interpreted by node correctly :( – Zane Claes Oct 15 '12 at 18:08
  • Btw, I had to do it this way: NODE_ENV=production forever start --max-old-space-size=8192 --nouse-idle-notification -c "node" index.js – Zane Claes Oct 15 '12 at 18:15
  • The problem is I'm not sure the "binary" forever will pass the env to node. To know for sure just output the env `console.log(process.env)` – 3on Oct 15 '12 at 18:31
  • Good call; that worked. Still no idea how to check if the --max-old-space-size and --nouse-idle-notification flags are getting passed though :( – Zane Claes Oct 15 '12 at 18:41
  • 1
    Unfortunately, I've confirmed that this is not passing the flags through to node. I added the --expose-gc flag which makes me able to use the gc() function when I start node with this flag, but the gc() function is undefined when I use this forever technique. – Zane Claes Oct 16 '12 at 05:08