Repo
Docs
Environment Variables

Using environment variables

We currently recommend using dotenv-cli as the simplest way to bring your environment variables into your development tasks.

We're actively looking forward to improving the developer experience and ergonomics for your environment variables in a future release of Turborepo.

With local turbo

  1. Place all of your variables into the root of your monorepo as a .env file.

  2. Install dotenv-cli into the root of your repository.

{
   "devDependencies": {
+    "dotenv-cli": "latest"
  }
}
  1. Adjust your scripts to inject the environment variables into the turbo command.
{
  "scripts": {
    "dev": "dotenv -- turbo dev"
  }
}

With global turbo

If you're using turbo globally, you'll also need to install dotenv-cli globally so you can put dotenv -- in front of the turbo command in your terminal.

With workspace scripts

You may prefer to make your workspaces responsible for loading environment variables. This approach is more flexible, if you don't mind the extra configuration overhead in your package.json scripts.

To use this strategy:

  1. Place all of your variables into the root of your monorepo as a .env file.

  2. Install dotenv-cli in the workspace.

{
  "scripts": {
+.   "dev": "dotenv -e ../../.env start-server"
  }
  "devDependencies": {
+    "dotenv-cli": "latest"
  },
}