Skip to content

For pnpm, Turborepo, and Nx monorepos

Env vars in a monorepo, without a .env to sync in every package.

One .envshed.json at the root maps each package to an Envshed project. envshed pull at the root writes every package's .env in one run. Personal overrides apply only to you.

In a monorepo, package A needs a Stripe key, package B needs a Postgres URL, and package C needs both. The next person on the team copies three files from Slack, misses one, and the app crashes at startup with undefined. Envshed keeps your package layout as it is and maps each package to a project.

Where monorepo secrets go wrong

  • Three packages, three .env files, one person keeping them in sync

    One engineer knows where every value lives. When they go on vacation, the new hire's setup breaks and nobody can reproduce it.

  • A new package ships on Tuesday, its keys are lost by Friday

    Nobody remembers which env vars belong to the package you added last sprint. The .env.example file drifts one value at a time.

  • Turbo caches a task with a missing env var

    The cache treats the missing key as a valid build output. The bug survives a week because the CI run that should have failed was served from cache.

A config that understands your workspace shape

One .envshed.json at the repo root maps each workspace to an Envshed project, an environment, and an output file. envshed pull at the root reads that map and writes each workspace's secrets to its file. pnpm workspaces, Turborepo, Nx, and Lerna read those files like any other .env.

Declare once, pull per workspace

One config file maps every package.

terminal
// .envshed.json at the repo root
{
  "org": "acme",
  "project": "platform",
  "defaultEnv": "development",
  "workspaces": {
    "apps/api":      { "project": "platform-api" },
    "apps/web":      { "project": "platform-web", "defaultEnv": "development" },
    "packages/auth": { "project": "platform-auth", "file": ".env.local" }
  }
}

What this replaces

  1. Workspace-scoped pulls

    envshed pull --workspace apps/api writes only the secrets of the project mapped to apps/api. A frontend workspace mapped to another project never receives the Stripe secret.

  2. Missing and placeholder keys, flagged

    Secret definitions list the keys a project expects. The project page shows each environment where a defined key is missing or holds only a placeholder. envshed pull lists the placeholders you have not overridden.

  3. Turborepo reads the same files

    envshed pull writes .env files on disk. List them in turbo.json globalDependencies, as the demo repo does, and a changed value changes the cache hash.

What you get

  • envshed init reads pnpm-workspace.yaml or package.json workspaces and lists the packages to map
  • Each workspace pulls only its project's secrets, so STRIPE_SECRET_KEY stays out of the frontend bundle
  • Personal overrides on top of shared values, for your own local DATABASE_URL
  • Works with pnpm workspaces, Turborepo, Nx, and Lerna
  • Every pull in the audit log with user, IP, and time

Monorepo-specific questions

  • Do I need a separate account per package?

    No. One organization holds every project. Each workspace in .envshed.json points to a project, and several workspaces can point to the same one.

  • Does it respect Turborepo's cache hashing?

    Yes, once turbo.json lists the .env files that envshed pull writes, in globalDependencies or in task inputs. The demo repo lists .env and **/.env.

  • Can different packages use different envs at the same time?

    Yes. Run envshed pull --workspace apps/api --env staging and envshed pull --workspace apps/web --env development side by side.

  • What if my monorepo has 80 packages?

    envshed init scans up to four directory levels and 500 directories, and you pick which packages to map. It does not turn libraries into projects on its own. Add a missed package with envshed workspace add and its path.

Want the full pattern with pnpm, Turborepo, and Nx walkthroughs? Read the full guide ↗

Stop diffing .env files across packages

envshed pull at the root writes every workspace's .env.

Start free

Part of the Envshed.