How to use environment variables in React apps

twitter logo ・1 min read

If you want to use environment variables in React, you need to prefix them with REACT_APP_, e.g. REACT_APP_API_URL.

When you start your React app, you will use export REACT_APP_API_URL=http://localhost:4200 && yarn run start then.

In your code, you can read the variable's content with process.env.REACT_APP_API_URL.

It took me two days to figure out that you need to use the prefix, so maybe this advice will safe you some time.

twitter logo DISCUSS (3)
markdown guide

Thanks for the tip, Matthias.

How were you able to figure it out?


That's a good question! After hours of trying and googling, I found this two GitHub issues which put me into the right direction:


Thanks again 👊

It seems like most of answers are out there but we need to weave'em together to solve a problem 🙂

Classic DEV Post from May 19 '19

Solving Puzzles With High-Performance JavaScript

Premature optimization is the root of all evil. It's also the root of this article. I like programmi...

Matthias 👨‍💻 profile image
Software Engineer. Always curious for new (☁️) technologies. Working on all stacks. Using Java, TypeScript, Bash, Docker, Kubernetes, macOS, ...

Signed up yet?

DEV is where coding careers are built.

Create Your Account