Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is an .env (or dotenv) file exactly?

Tags:

dotenv

There's a lot of programs out there that can utilize .env files. Most of them support the basic bash-syntax, others support more advanced things like templating within the .env files. The way you're supposed to use .env files varies a lot as well. Often in this context, you'll year from the 12-factor-app which states that you should export (some) configuration as environment variables, that apparently lead to two use cases:

  • Some dotenv programs do just that: you prefix your command on the shell with dotenv and the variables in the dotenv file will magically be available in you process.
  • Others however provide libraries that actually read .env files from within your code -- a very different approach since your code is suddenly interpreting .env files directly and does not "see" the environment variables anymore.

Since there's so many different interpretations of usage, use-cases and syntax, is there a proper definition of .env files or some commonly accepted standard? If not, at least some historical references?

like image 264
Bastian Venthur Avatar asked Sep 07 '25 18:09

Bastian Venthur


1 Answers

It appears that .env files lack a complete definition.

This reference:

https://devcenter.heroku.com/articles/heroku-local

Links here:

http://blog.daviddollar.org/2011/05/06/introducing-foreman.html

Which leads here:

https://ddollar.github.io/foreman/

Which contains this:

ENVIRONMENT
    If a .env file exists in the current directory, the default
    environment will be read from it. This file should contain key/value
    pairs, separated by =, with one key/value pair per line.

        FOO=bar
        BAZ=qux
like image 199
davejagoda Avatar answered Sep 12 '25 05:09

davejagoda