KnewB
KnewB

Reputation: 363

How is NODE_ENV set in OpenShift?

I've read of the dangers of not having NODE_ENV properly set in Express. In my OpenShift app, I can display NODE_ENV through a simple Express route and a console.log statement, but I can't see it anywhere else, e.g. with the env command at the SSH prompy. How/where is it set?

Upvotes: 0

Views: 842

Answers (1)

Math
Math

Reputation: 187

In mine (and this differs from what you might find in the documentation), it's set in a file at nodejs/configuration/node.env in the gear. To reach it, you can use the cloud console tools - rhc ssh -a your-app-name. In that file, you should see something like

#This file specifies the environment to setup prior to running Node.
...
#  Default script name used is server.js
export node_app=server.js
#Any arguments to pass to the application or script.
export node_app_args=""

#Any command line options to pass to Node.
#E.g. export node_opts="--stack-size=2048 --trace_gc"

export node_opts=""
...
#Node production mode turned on by default
export NODE_ENV=${NODE_ENV:-"production"} 

...which also lets you set up other configuration options. Hope that helps, it took a bit of searching when I first had to do it.

Upvotes: 3

Related Questions