How can we 'transfer' PLATFORM_VARIABLES into Node's process.env?

Environment variables entered via the ManagementConsole are stored in $PLATFORM_VARIABLES. In Node, we would need to have them in process.env so that these UI-entered values override statically defined values in the code.

One possible approach seems to be to for us to use ‘platformsh-config’ reader, read the values and push them into process.env as part of ‘npm start’ flow. Is there a different / better approach ?

If they’re just arbitrary values, the easiest way is generally to prefix the variable name with env: in the UI. That way, they also get replicated as their own stand-alone Unix environment variables with that name (minus the prefix). So, if you make a variable named env:ADMIN_NAME, it will result in a normal env var accessible in process.env named ADMIN_NAME.



We tried that with one of our variables (env:PUBLIC_URL) but didn’t see it being available as expected. Not sure what we did wrong. We wanted to use it in react app->index.html as %PUBLIC_URL%

Is it possible that you’re missing the prefix (env:)?

• Variables beginning with env: will be exposed as Unix environment variables
• Variables beginning with php: will be interpreted as php.ini directives.
• All other variables will be part of the environment $PLATFORM_VARIABLES variable

The other detail to always look out for is whether you are using environment variables or project variables. I think for the env:PUBLIC_URL it would be an environment variable, but I just wanted to make sure you knew there were both options.

Screen Shot 2020-12-10 at 12.17.43 Screen Shot 2020-12-10 at 12.17.59

The env: prefix works the same for both project-level and environment-level variables. However, setting a project-level variable won’t trigger a redeploy so the variable change won’t take effect until you redeploy manually. That’s another possibility.

If it’s none of those, you may want to contact support so they can look at your project specifically.