Confuse if .env file should still be filled up in NEXT.JS?

327 Views Asked by At

Im a little confused whether we should fill up or leave .env file empty as it is? Since during execution each environment file (.env.dev / .env.production) will append all my values into .env

So what I'm saying is, keeping .env empty and only append env values into each environment files.

.env -> keep it empty

.env.developemnt -> env specific values

.env.development.local -> store all kind of secrets

#.gitignore
.env.development.local

Or, is there a "proper" way to handle this instead?

1

There are 1 best solutions below

0
PYTHON DEVELOPER999 On

Environment variables are looked up in the following places, in order, stopping once the variable is found.

process.env
.env.$(NODE_ENV).local
.env.local (Not checked when NODE_ENV is test.)
.env.$(NODE_ENV)
.env

For example, if NODE_ENV is development and you define a variable in both .env.development.local and .env, the value in .env.development.local will be used.

In other words, the first .env to match the order will be loaded.

You can delete .env if you don't use it.

https://nextjs.org/docs/basic-features/environment-variables#environment-variable-load-order