Saravanan S
Saravanan S

Reputation: 1043

nodejs openshift cartridge - not reading custom environment variables

I am identifying my openshift nodejs app environment through system environment variables Ex: 'staging', 'production'. My custom environment variable name is OPENSHIFT_APP_ENV. I have set this in .bash_profile and ran source .bash_profile.

When I did printenv or echo $OPENSHIFT_APP_ENV in command line in my openshift app, I can see the values set properly.

But these variables are not read/set in my nodejs app. I am simply trying to read it as global.ENV = process.env.OPENSHIFT_APP_ENV || "development";

I feel that it should be simple setting issue, but could not get this working somehow. Any help will be appreciated.

Upvotes: 0

Views: 335

Answers (1)

user2879327
user2879327

Reputation:

You should use the rhc env set command as explained in this section (https://developers.openshift.com/en/managing-environment-variables.html#custom-variables) of the Developer Center to set your environment variables. Especially if you are using a scaled application, that makes sure that your custom environment variables are created on all gears.

It is also standard practice (i believe) to use the NODE_ENV environment variable to determine what environment you are operating in.

You should also make sure to stop & start (not restart) your application after you create environment variables to make sure that your process picks them up correctly (may solve your issue of your application not seeing the ones from your .bash_profile, but i would still recommend using the rhc env set command instead)

Upvotes: 1

Related Questions