Skip to content

Commit 9fca2a4

Browse files
fixup! Document the new .env support for local development
1 parent 8887405 commit 9fca2a4

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/content/partials/workers/secrets-in-dev.mdx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,27 @@
22
{}
33
---
44

5-
To define variables to use in local development that you do not want to store in Wrangler config (for example secrets that are defined for production deployment in [Wrangler configuration file](/workers/configuration/environment-variables/#compare-secrets-and-environment-variables)), create either a `.dev.vars` file, or a `.env` file in the root of your project.
6-
You should use either `.dev.vars` or `.env` but not both. If you define a `.dev.vars` file, then values in `.env` files will be ignored for local development.
5+
Put secrets for use in local development in either a `.dev.vars` file or a `.env` file, in the root of your project.
76

8-
The `.dev.vars` and `.env` files should be formatted using the `dotenv` syntax, such as `KEY="VALUE"`:
7+
:::note
8+
Do not add secrets as `vars` in your Worker's Wrangler configuration file.
9+
:::
10+
11+
Choose to use either `.dev.vars` or `.env` but not both. If you define a `.dev.vars` file, then values in `.env` files will be ignored for local development.
12+
13+
:::note
14+
The `.dev.vars` and `.env` files should not committed to git. Add `.dev.vars*` and `.env*` to your project's `.gitignore` file.
15+
:::
16+
17+
These files should be formatted using the [dotenv](https://hexdocs.pm/dotenvy/dotenv-file-format.html) syntax. For example:
918

1019
```bash title=".dev.vars / .env"
1120
SECRET_KEY="value"
1221
API_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
1322
```
1423

1524
To set different secrets for each Cloudflare environment, create files named `.dev.vars.<environment-name>` or `.env.<environment-name>`.
25+
1626
When you select a Cloudflare environment in your local development, the corresponding environment-specific file will be loaded ahead of the generic `.dev.vars` (or `.env`) file.
1727

1828
- When using `.dev.vars.<environment-name>` files, all secrets must be defined per environment. If `.dev.vars.<environment-name>` exists then only this will be loaded; the `.dev.vars` file will not be loaded.
@@ -23,5 +33,7 @@ When you select a Cloudflare environment in your local development, the correspo
2333
- `.env` (least specific)
2434

2535
:::note
26-
To include every environment variable defined in your system's process environment as a local development variable, ensure there is no `.dev.vars` and then set the `CLOUDFLARE_INCLUDE_PROCESS_ENV` environment variable to `true`.
36+
To disable loading local dev vars from `.env` files without providing a `.dev.vars` file, set the `CLOUDFLARE_LOAD_DEV_VARS_FROM_DOT_ENV` environment variable to `"false"`.
37+
38+
To include every environment variable defined in your system's process environment as a local development variable, ensure there is no `.dev.vars` and then set the `CLOUDFLARE_INCLUDE_PROCESS_ENV` environment variable to `"true"`.
2739
:::

0 commit comments

Comments
 (0)