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
### Configuring different environments in Wrangler
51
+
52
+
You can set up [environments in Wrangler](/workers/wrangler/environments), and specify different values for your environment variables in each environment.
51
53
`vars` is a non-inheritable key. [Non-inheritable keys](/workers/wrangler/configuration/#non-inheritable-keys) are configurable at the top-level, but cannot be inherited by environments and must be specified for each environment.
52
54
53
-
To define environment variables for different environments, refer to the example below:
55
+
The example below sets up two environments, `staging` and `production`, with different values for `API_HOST` and `API_ACCOUNT_ID`.
For local development with `wrangler dev`, variables in the [Wrangler configuration file](/workers/wrangler/configuration/) are automatically overridden by any values defined in a `.dev.vars` file located in the root directory of your worker. This is useful for providing values you do not want to check in to source control.
74
-
75
-
```shell
76
-
API_HOST = "localhost:4000"
77
-
API_ACCOUNT_ID = "local_example_user"
78
-
```
75
+
To run Wrangler commands in specific environments, you can pass in the `--env` or `-e` flag. For example, you can develop the Worker in the `dev` environment by running `npx wrangler dev -e=staging`, and deploy it with `npx wrangler deploy -e=production`.
79
76
80
-
Alternatively, you can specify per-environment values in the [Wrangler configuration file](/workers/wrangler/configuration/) and provide an `environment` value via the `env` flag when developing locally like so `wrangler dev --env=local`.
77
+
Learn about [environments in Wrangler](/workers/wrangler/environments).
81
78
82
79
## Add environment variables via the dashboard
83
80
@@ -94,14 +91,14 @@ To add environment variables via the dashboard:
94
91
95
92
:::caution[Plaintext strings and secrets]
96
93
97
-
98
94
Select the **Secret** type if your environment variable is a [secret](/workers/configuration/secrets/).
99
95
100
-
101
96
:::
102
97
103
98
<Renderfile="env_and_secrets" />
104
99
100
+
<Renderfile="secrets-in-dev" />
101
+
105
102
## Related resources
106
103
107
-
* Learn how to access environment variables in [ES modules syntax](/workers/reference/migrate-to-module-workers/) for an optimized experience.
104
+
- Migrating environment variables from [Service Worker format to ES modules syntax](/workers/reference/migrate-to-module-workers/#environment-variables).
0 commit comments