49

How can I set the NODE_ENV variable/parameter to "production" when I'm using forever to start my node script

I got this so far:

forever start -l forever.log -o out.log -e err.log -a app.js
Cœur
  • 34,719
  • 24
  • 185
  • 251
Philipp Kyeck
  • 17,628
  • 15
  • 79
  • 117

1 Answers1

87

You can set NODE_ENV as normal and then run forever:

NODE_ENV=production forever [flags] start app.js [app_flags]

The initial NODE_ENV will be preserved when the server restarts - behaviour that was fixed in this issue:

https://github.com/nodejitsu/forever/issues/116

Older versions of forever can use the following command line format:

NODE_ENV=production forever [flags] app.js
cjohn
  • 10,730
  • 3
  • 29
  • 17
  • but how do i set it "as normal"? – Philipp Kyeck Oct 06 '11 at 14:20
  • I could have been more specific and said, "without forever" instead of "as normal". But: NODE_ENV=production forever app.js – cjohn Oct 06 '11 at 14:43
  • This issue has been fixed to work on restarts: https://github.com/nodejitsu/forever/issues/search?q=116. – Chris B. Feb 09 '12 at 03:13
  • Don't know if this help, and you might have meant this with [Flags] but NODE_ENV=production forever start app.js is how I got it to work. Without it, it doesn't actually do the forever part. – binarygiant Mar 14 '13 at 16:19
  • @binarygiant That appears to be an update to forever's API. I'll update the original answer with the new information. – cjohn Mar 14 '13 at 17:55