Search code examples
reactjsnode.jsenvironment-variablescircleci

Access environment variable set up in circleci project in the application


I have set up an environment variable in the circle ci project like this. I am trying to access it in a js file. So I exported the variable in circle ci yaml file like this:


    jobs:
      build:
        ...
        steps:
          - run: 
              command: |
              echo 'export ENV_VAR="$ENV_VAR"' >> "$BASH_ENV"
                source "$BASH_ENV"

And I am trying to access in a js file as process.env.ENV_VAR but I am getting undefined.


Solution

  • All custom variables you need to access in a js file should be named with the prefix REACT_APP_ For more info, this link can be referred to.