DEV Community

Cover image for How To use .env in Reactjs
Ayoub
Ayoub

Posted on

How To use .env in Reactjs

To use .env in react :

1.You need to create .env file .

2.Open the .env file and declare your environment variable.

REACT_APP_NAME=react app
REACT_APP_CLIENT_ID=adkksclsc.cscd52

Enter fullscreen mode Exit fullscreen mode

Note: React enforces the prefix REACT_APP on every custom variable. Variable without REACT_APP is ignored. So always create a custom variable like REACT_APP_CUSTOM_VARIABLE.

3.Now to print your environment variable you need to put process.env before your custom variable.

{process.env.REACT_APP_NAME}
Enter fullscreen mode Exit fullscreen mode

4.Now start your application npm start and refresh the browser to see the changes.

Top comments (0)