You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/partials/workers/secrets-in-dev.mdx
+16-4Lines changed: 16 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,17 +2,27 @@
2
2
{}
3
3
---
4
4
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.
7
6
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:
9
18
10
19
```bash title=".dev.vars / .env"
11
20
SECRET_KEY="value"
12
21
API_TOKEN="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
13
22
```
14
23
15
24
To set different secrets for each Cloudflare environment, create files named `.dev.vars.<environment-name>` or `.env.<environment-name>`.
25
+
16
26
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.
17
27
18
28
- 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
23
33
-`.env` (least specific)
24
34
25
35
:::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"`.
0 commit comments