Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node/express: set NODE_ENV when using Forever to run script continuously

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 
like image 864
Philipp Kyeck Avatar asked Oct 06 '11 12:10

Philipp Kyeck


People also ask

What is setting NODE_ENV?

Node. js assumes it's always running in a development environment. You can signal Node. js that you are running in production by setting the NODE_ENV=production environment variable. This is usually done by executing the command.

What does NODE_ENV default to?

We see that it in fact reads NODE_ENV and defaults to 'development' if it isn't set. This variable is exposed to applications via 'app. get(“env”)' and can be used to apply environment specific configurations as explained above, but it's up to you to use this or not.

What does NODE_ENV mean?

NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).

Does jest set NODE_ENV?

Jest automatically defines environment variable NODE_ENV as test (see https://jestjs.io/docs/environment-variables), as you can confirm from your error message: console.


1 Answers

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
like image 172
cjohn Avatar answered Sep 29 '22 12:09

cjohn