Skip to main content

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

Comments

5 comments

  • Larry

    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.

    See: https://docs.platform.sh/development/variables.html#top-level-environment-variables

    Cheers.

    0
  • Permanently deleted user

    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%

    0
  • Platform.sh DevRel

    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

    0
  • Platform.sh DevRel

    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

    0
  • Larry

    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.

    0

Please sign in to leave a comment.