1

I want to share environment variables for my Node backend and my React frontend (create react app). I have followed below guide to set up the project.

https://medium.com/@chloechong.us/how-to-deploy-a-create-react-app-with-an-express-backend-to-heroku-32decfee6d18

Since my folder structure looks like below:

|project
|---.env <-- Want to use both for Node and React.
|---package.json <-- Node
|---client
|---|---package.json <-- React
|---|---src
|---|---|---index.js
|---|---|---app.js <-- Here I want to access .env in project root

The React app looks for it´s .env file in the client folder root but I want to specify the path for it uses the .env file in project root.

How can I specify the path in the React-frontend so it uses the .env file in project root?

Thanks in advance.

2
  • Possible duplicate of create react app not picking up .env files? Commented Sep 3, 2019 at 19:40
  • 1
    The front end shouldn't have access to .env if I'm not mistaken. That's where all your database usernames and passwords and such live. Commented Sep 3, 2019 at 19:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.