strboul blog

Direnv supports .env files


direnv is a fantastic tool that automatically loads environment variables when you switch directories.

By default, direnv works with .envrc files, but it can also load .env files automatically. This feature isn’t prominently documented, but thanks to this GitHub comment, there's a simple way to do it.

Add the following line to your .envrc file:

dotenv_if_exists .env

Then, allow direnv to apply the changes:

direnv allow

Now, whenever you enter the directory, direnv will automatically load the .env.