Using Environment variables is very important to keep your private information secure.
It may contain your API keys or database credentials or an...
For further actions, you may consider blocking this person and/or reporting abuse
do we need to activate any .env file ?
like sometimes, i have to activate some env files in the bash shell like
source ./example.env
and if we create a file through
.env.prod
what package do we need to install ?
like
dotenv
?instead ofnpm-cmd
it is looking very complexand how to use
.env.prod
is it same like
process.env.prod.SOME_KEY
??There is no need of activating .env file. For .env.prod you can use the env-cmd npm package and use it as shown below:
So when you run
npm run start
command, all .env.dev environment variables will be available through process.env.some_key and when you runnpm run start-prod
command, all .env.prod environment variables will be available through process.env.some_key only.ok you left one point , please answer that too
i have asked, that if i have .env.dev file
and i have some key as
then how do i need to use it?
Do i need to use it as
or
you need to use process.env.SOME_KEY only. Also don't add spaces before and after the
=
sign in .env fileokay thankyou sir, i will definitely try this
so,
and importing it as
I think this is fine now
Yes, it looks fine
Hi,
Great Post !
But how to get environement values from Azure App Service, Say we are using Linux machine and how to access the appsetting values from ReactJS?
The process.env.APPSETTING_Variable returns values when we try that in the apps service shell, but the same isnt returning values in the app once deployed.
could you post a solution on this?
@monicaadikesavan sorry but I never worked with Azure App service so can't help you with that
Thanks, But how can we handle deployment variables without .env file in ReactJS, Can you help on that ?
@monicaadikesavan Every hosting provider provides a way to add environment variables from UI as I have shown in the screenshot at the end of this article, you can add environment variables from
build & deploy
section.Hi Yogesh,
Thanks For the article,
I need to know more on the point below
"Also, you need to make sure that, you add the environment variables file name to your .gitignore file so it will not be added to your Git repository when you push the code to the repository."
So if we do not push the env.prod file in GIT how cum the env will able to use this.
Another, we supply a build package normally, and do not run the start cmd on PRD.
So how it will work in that case
Thanks
dotenv is the way to go.
Yes, that's my favorite way
npm run build what will be it's default environment.