Reputation: 749
I am encountering something strange here and hope to find out if I have missed anything. Here is the thing, I have a .env file with this value here:SITE_URL=http://localhost:5000 and when I tried console.log(process.env.SITE_URL), it returned undefined. But the strange thing is when I changed .env file value to REACT_APP_FETCH_URL=http://localhost:5000 and did a console.log(process.env.REACT_APP_FETCH_URL), it returned http://localhost:5000.
I am not sure what is going on? Any help greatly appreciated and many thanks in advance.
Upvotes: 0
Views: 75
Reputation: 9063
I'm guessing you're using create-react-app
. In CRA you need to prefix your environment variables with REACT_APP_
in order for them to be accessible under provess.env
.
You can check documentation about it here: https://create-react-app.dev/docs/adding-custom-environment-variables/
Upvotes: 1