---
title: Environment variables and secrets · Cloudflare Workers docs
description: Configuring environment variables and secrets for local development
source_url:
  html: https://angela-ssl-tls-updates.preview.developers.cloudflare.com/workers/local-development/environment-variables/index.md
  md: https://angela-ssl-tls-updates.preview.developers.cloudflare.com/workers/local-development/environment-variables/
---

During local development, you may need to configure **environment variables** (such as API URLs, feature flags) and **secrets** (API tokens, private keys). You can use a `.dev.vars` file in the root of your project to override environment variables for local development, and both [Wrangler](https://developers.cloudflare.com/workers/configuration/environment-variables/#compare-secrets-and-environment-variables) and the [Vite plugin](https://developers.cloudflare.com/workers/vite-plugin/reference/secrets/) will respect this override.

Warning

Be sure to add `.dev.vars` to your `.gitignore` so it never gets committed.

### Why use a `.dev.vars` file?

Use `.dev.vars` to set local overrides for environment variables that should not be checked into your repository.

If you want to manage environment-based configuration that you **want checked into your repository** (for example, non-sensitive or shared environment defaults), you can define [environment variables as `[vars]`](https://developers.cloudflare.com/workers/wrangler/environments/#_top) in your Wrangler configuration. Using a `.dev.vars` file is specifically for local-only secrets or configuration that you do not want in version control and only want to inject in local dev sessions.

## Basic setup

1. Create a `.dev.vars` file in your project root.

2. Add key-value pairs:

   ```ini
   API_HOST="localhost:3000"
   DEBUG="true"
   SECRET_TOKEN="my-local-secret-token"
   ```

3. Run your `dev` command

   **Wrangler**

   * npm

     ```sh
     npx wrangler dev
     ```

   * pnpm

     ```sh
     pnpm wrangler dev
     ```

   * yarn

     ```sh
     yarn wrangler dev
     ```

   **Vite plugin**

   * npm

     ```sh
     npx vite dev
     ```

   * pnpm

     ```sh
     pnpm vite dev
     ```

   * yarn

     ```sh
     yarn vite dev
     ```

## Multiple local environments with `.dev.vars`

To simulate different local environments, you can:

1. Create a file named `.dev.vars.<environment-name>` . For example, we'll use `.dev.vars.staging`.

2. Add key-value pairs:

   ```ini
   API_HOST="staging.localhost:3000"
   DEBUG="false"
   SECRET_TOKEN="staging-token"
   ```

3. Specify the environment when running the `dev` command:

   **Wrangler**

   * npm

     ```sh
     npx wrangler dev --env staging
     ```

   * pnpm

     ```sh
     pnpm wrangler dev --env staging
     ```

   * yarn

     ```sh
     yarn wrangler dev --env staging
     ```

   **Vite plugin**

   * npm

     ```sh
     CLOUDFLARE_ENV=staging npx vite dev
     ```

   * pnpm

     ```sh
     CLOUDFLARE_ENV=staging pnpm vite dev
     ```

   * yarn

     ```sh
     CLOUDFLARE_ENV=staging yarn vite dev
     ```

   Only the values from `.dev.vars.staging` will be applied instead of `.dev.vars`.

## Learn more

* To learn how to configure multiple environments in Wrangler configuration, [read the documentation](https://developers.cloudflare.com/workers/wrangler/environments/#_top).
* To learn how to use Wrangler environments and Vite environments together, [read the Vite plugin documentation](https://developers.cloudflare.com/workers/vite-plugin/reference/cloudflare-environments/)
