Answer the question
In order to leave comments, you need to log in
Where to store the (access_token) env key in create-react-app (CRA)?
Good afternoon. There was a need to store an access token for the API, as I understand it, there is a place in CRA (create react app) where you can store it, and it seems that you need to dig into the env line - a parameter. Can anyone suggest how to do this? You are welcome.
Answer the question
In order to leave comments, you need to log in
Short instructions:
1. Create an .env file in the project root with content like this REACT_APP_USER_TOKEN=Put token here
2. Create a .env.local file in the project root with the same content as .env, but instead of Put token here , insert the real key.
3. Add a rule to .gitignore: .env*.local
4. npm run start
-- it is very important to build the project when changing environment variables.
The value of a variable is accessed by calling process.env.REACT_APP_USER_TOKEN
Full instruction
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question