Encrypt .env files in a monorepo

Load shared or workspace-specific encrypted .env files across a monorepo.

Point -f at a directory and dotenvx loads the .env inside it. This makes a shared root .env available from any workspace.

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

Load the root .env

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

$ 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 Nx and Turborepo for workspace-specific examples.