thiagowfx's avatar

Β¬ just serendipity πŸ€ (not just serendipity)

direnv: automatically load .env everywhere

β€’ 92 words β€’ 1 min β€’ updated

Previously, previously.

Problem statement: Given a monorepo with various scattered .env files, how to ensure each one of them is automatically loaded when changing directories?

We could create sibling .envrc files in each directory, with the following content:

shell
#!/bin/sh
dotenv

Documentation.

But this is cumbersome!

Also, perhaps your teammates simply do not want to use direnv.

Here’s a more robust approach:

~/.config/direnv/direnv.toml toml
[global]
load_dotenv = true

This ensures every .env file is automatically loaded. No need to splatter dotenv everywhere!

I have accidentally discovered this is possible via this issue.