Use directories with monorepos

Use directories to load shared env files across a monorepo.

Point -f at a directory and dotenvx loads the .env inside it. This keeps workspace commands short and makes a shared root .env available from anywhere in the repository.

my-monorepo/
  .env
  .env.keys
  apps/
    web/
      index.js

Load the root .env

From apps/web, point -f two directories up:

$ dotenvx get HELLO -f ../..
World

$ dotenvx run -f ../.. -- node index.js
⟐ injected env (1) from ../../.env
Hello World

Encrypted values work without extra configuration when .env.keys sits beside the resolved .env.

Use a convention

With a convention, the directory becomes the base for every convention file:

$ dotenvx run -f ../.. --convention=nextjs -- node index.js
⟐ injected env (1) from ../../.env.development.local, ../../.env.local, ../../.env.development, ../../.env
Hello development local

Share only .env.keys

If a workspace has its own .env but uses the root .env.keys, point -fk at the root directory:

$ dotenvx run -f . -fk ../.. -- node index.js

See the Nx guide and Turborepo guide for framework-specific setup.