I’m trying to use my api key as an env variable in my react application by defining it in the .env file. However when run "npm run dev" I get the console error process is not defined from lines
main.jsx
import dotenv from 'dotenv'
dotenv.config()
and
component.jsx
const api_url =env.REACT_APP_API_URL
Ive setup my env var as follows:
REACT_APP_API_URL = "http://127.0.0.1:5000/upload"
2
Answers
use process.env.REACT_APP_API_URL, also you don’t need to import dotenv
create-react-app provides this functionality out of the box, assuming you’re using [email protected] or higher
I think you missed the word
process
in yourcomponent.jsx
file.You might check this line;
=>