Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

undefined environment variables in Reactjs

I am new to React and I want to use Evironment Variables in my App. I tried out many solutions from the web but nothing worked out so here is my configuration:
i created a process.env file in my root directory and inside this file I initialized my variables like this:

REACT_APP_SERVICE_ID=key
REACT_APP_TEMPLATE_ID=key_2
REACT_APP_API_KEY=key_3

after I called them in my component like so:

const serviceId = process.env.REACT_APP_SERVICE_ID;
const templateId = process.env.REACT_APP_TEMPLATE_ID;
const public_key = process.env.REACT_APP_API_KEY;

but when i log them, the console shows undefined. I also tried out using dotenv-webpack , even that doesn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

rename the filename from process.env to .env

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading