- Install
dotenv
package - Create .env file in root directory
- Add variables to the file like this:
REACT_APP_MOCK_API_URL=data1
REACT_APP_REST_KEY=data2
- Read variables like this:
const key = process.env.REACT_APP_REST_KEY;
const mockUrl = process.env.REACT_APP_MOCK_API_URL;
Important!
Variable name MUST begin with "REACT_APP_"
(Initially I called variable MOCK_API_URL. It took me few hours to figure out why key contained value and mockUrl was undefined.)