.env file

Damaris Göbel
1 min readOct 4, 2021

A .env file is a simple configuration text file that is used to define some variables you want to pass into your application’s environment.

* .env.local: Local overrides. This file is loaded for all environments except test.

To read these values, there are a couple of options, but the easiest is to use the dotenv package from npm.

In React .env file is available with this feature react-scripts@0.2.3 and higher.

So if you have a react app, you don’t need to add dotenv as a package to your project.

For example, having an environment variable named REACT_APP_NOT_SECRET_CODE will be exposed in your JS as process.env.REACT_APP_NOT_SECRET_CODE.

What other .env files can be used?

* .env: Default.

* .env.local: Local overrides. This file is loaded for all environments except test.

* .env.development, .env.test, .env.production: Environment-specific settings.

* .env.development.local, .env.test.local, .env.production.local: Local overrides of environment-specific settings.

You shouldn’t commit your .env file

It should only include environment-specific values such as database passwords or API keys.

If you change anything in an env file you have to start the app again to get the updated variables from the file. It doesn’t update automatically.

--

--

Damaris Göbel

I like to do crazy things with CSS & JavaScript. My brain occasionally runs out of memory so I need to write down my thoughts.