If you’ve used Create React App, you can set up and use environment variables out of the box as you’ll have a NODE_ENV defined for you named REACT_APP_ which you can reference with process.env.REACT_APP_. Otherwise, you’ll need to install the dotenv package via npmjs.com’s library and follow the documentation to define and configure your variable. Read post
{
"@timestamp": "2022-06-08T13:20:19+00:00",
"slug": "/how-to-create-an-environment-variable-in-a-react-app",
"post_type": "post",
"@tags": [
"react"
],
"@categories": [
"All",
"React"
],
"excerpt": "If you’ve used Create React App, you can set up and use environment variables out of the box as you’ll have a NODE_ENV defined for you named REACT_APP_ which you can reference with process.env.REACT_APP_. Otherwise, you’ll need to install the dotenv package via npmjs.com’s library and follow the documentation to define and configure your variable. […]"
}