score:3

Accepted answer

Your app was made with create-react-app. Here are the docs for adding / referencing environment variables: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md#adding-custom-environment-variables

Create a file in the root folder called .env with the contents:

REACT_APP_XREFS_BACK_URL=put_whatever_here

Then access this variable in your JavaScript via:

process.env.REACT_APP_XREFS_BACK_URL

score:0

Dont sure, if it actual for you, CNDyson, but I think it might be helpful for newers like me:

  1. npm install --save dotenv
  2. create .env file in the root directory
  3. declare there REACT_APP_**VARIABLE_NAME** = dont forget about REACT_APP
  4. use it like this: process.env.REACT_APP_**VARIABLE_NAME**

Highly recommend to explore these links:

https://create-react-app.dev/docs/adding-custom-environment-variables/ -official documentaion

https://www.npmjs.com/package/dotenv - dotenv

score:0

The problem is that usually you want to access the environments variables present on the server that host your application.

With the described solution you will never be able to do docker run --env FOO="value of foo" my-org/my-app then access FOO in the app like process.env["FOO"].

create-react-app bundle the environment variables that are defined when you run yarn build.

If you want, for example, access the environment variables defined in the docker container check out: react-envs

image

image

score:0

At first create a file named env.local beside package.json and try to secure environment variables REACT_APP_YOUR ENV FILE NAME

now set the secured name to your firebase file and push it

as simple as that


Related Query

More Query from same tag