Skip to content

Commit 08568e5

Browse files
update system environment variables page
1 parent 21eb4ad commit 08568e5

File tree

1 file changed

+39
-32
lines changed

1 file changed

+39
-32
lines changed

src/content/docs/workers/wrangler/system-environment-variables.mdx

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@ pcx_content_type: configuration
33
title: System environment variables
44
head: []
55
description: Local environment variables that can change Wrangler's behavior.
6-
76
---
87

9-
import { Render, Type, MetaInfo } from "~/components"
8+
import { Render, Type, MetaInfo } from "~/components";
109

1110
System environment variables are local environment variables that can change Wrangler's behavior. There are three ways to set system environment variables:
1211

@@ -21,58 +20,66 @@ System environment variables are local environment variables that can change Wra
2120
To set different system environment variables for each environment, create files named `.env.<environment-name>`. When you use `wrangler <command> --env <environment-name>`, the corresponding environment-specific file will be loaded instead of the `.env` file, so the two files are not merged.
2221
:::
2322

24-
## Supported environment variables
23+
:::note
24+
During local development, the values in `.env` files are also loaded into the `env` object in your Worker, so you can access them in your Worker code.
2525

26-
Wrangler supports the following environment variables:
26+
For example, if you set `API_HOST="localhost:3000"` in your `.env` file, you can access it in your Worker like this:
2727

28+
```js
29+
const apiHost = env.API_HOST;
30+
```
2831

32+
See the [Environment variables and secrets](/workers/development-testing/environment-variables/) page for more information on how to use `.env` files in local development.
33+
:::
2934

30-
* `CLOUDFLARE_ACCOUNT_ID` <Type text="string" /> <MetaInfo text="optional" />
35+
## Supported environment variables
3136

32-
* The [account ID](/fundamentals/account/find-account-and-zone-ids/) for the Workers related account.
37+
Wrangler supports the following environment variables:
3338

34-
* `CLOUDFLARE_API_TOKEN` <Type text="string" /> <MetaInfo text="optional" />
39+
- `CLOUDFLARE_ACCOUNT_ID` <Type text="string" /> <MetaInfo text="optional" />
3540

36-
* The [API token](/fundamentals/api/get-started/create-token/) for your Cloudflare account, can be used for authentication for situations like CI/CD, and other automation.
41+
- The [account ID](/fundamentals/account/find-account-and-zone-ids/) for the Workers related account.
3742

38-
* `CLOUDFLARE_API_KEY` <Type text="string" /> <MetaInfo text="optional" />
43+
- `CLOUDFLARE_API_TOKEN` <Type text="string" /> <MetaInfo text="optional" />
3944

40-
* The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`.
45+
- The [API token](/fundamentals/api/get-started/create-token/) for your Cloudflare account, can be used for authentication for situations like CI/CD, and other automation.
4146

42-
* `CLOUDFLARE_EMAIL` <Type text="string" /> <MetaInfo text="optional" />
47+
- `CLOUDFLARE_API_KEY` <Type text="string" /> <MetaInfo text="optional" />
4348

44-
* The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`.
49+
- The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`.
4550

46-
* `WRANGLER_SEND_METRICS` <Type text="string" /> <MetaInfo text="optional" />
51+
- `CLOUDFLARE_EMAIL` <Type text="string" /> <MetaInfo text="optional" />
4752

48-
* Options for this are `true` and `false`. Defaults to `true`. Controls whether Wrangler can send anonymous usage data to Cloudflare for this project. You can learn more about this in our [data policy](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md).
53+
- The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`.
4954

50-
* `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`<Type text="string" /> <MetaInfo text="optional" />
55+
- `WRANGLER_SEND_METRICS` <Type text="string" /> <MetaInfo text="optional" />
5156

52-
* The [local connection string](/hyperdrive/configuration/local-development/) for your database to use in local development with [Hyperdrive](/hyperdrive/). For example, if the binding for your Hyperdrive is named `PROD_DB`, this would be `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_PROD_DB="postgres://user:[email protected]:5432/testdb"`. Each Hyperdrive is uniquely distinguished by the binding name.
57+
- Options for this are `true` and `false`. Defaults to `true`. Controls whether Wrangler can send anonymous usage data to Cloudflare for this project. You can learn more about this in our [data policy](https://github.com/cloudflare/workers-sdk/tree/main/packages/wrangler/telemetry.md).
5358

54-
* `CLOUDFLARE_API_BASE_URL` <Type text="string" /> <MetaInfo text="optional" />
59+
- `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`<Type text="string" /> <MetaInfo text="optional" />
5560

56-
* The default value is `"https://api.cloudflare.com/client/v4"`.
61+
- The [local connection string](/hyperdrive/configuration/local-development/) for your database to use in local development with [Hyperdrive](/hyperdrive/). For example, if the binding for your Hyperdrive is named `PROD_DB`, this would be `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_PROD_DB="postgres://user:[email protected]:5432/testdb"`. Each Hyperdrive is uniquely distinguished by the binding name.
5762

58-
* `WRANGLER_LOG` <Type text="string" /> <MetaInfo text="optional" />
63+
- `CLOUDFLARE_API_BASE_URL` <Type text="string" /> <MetaInfo text="optional" />
5964

60-
* Options for Logging levels are `"none"`, `"error"`, `"warn"`, `"info"`, `"log"` and `"debug"`. Levels are case-insensitive and default to `"log"`. If an invalid level is specified, Wrangler will fallback to the default. Logs can include requests to Cloudflare's API, any usage data being collected, and more verbose error logs.
65+
- The default value is `"https://api.cloudflare.com/client/v4"`.
6166

62-
* `WRANGLER_LOG_PATH` <Type text="string" /> <MetaInfo text="optional" />
67+
- `WRANGLER_LOG` <Type text="string" /> <MetaInfo text="optional" />
6368

64-
* A file or directory path where Wrangler will write debug logs. If the path ends in `.log`, Wrangler will consider this the path to a file where all logs will be written. Otherwise, Wrangler will treat the path as a directory where it will write one or more log files using a timestamp for the filenames.
69+
- Options for Logging levels are `"none"`, `"error"`, `"warn"`, `"info"`, `"log"` and `"debug"`. Levels are case-insensitive and default to `"log"`. If an invalid level is specified, Wrangler will fallback to the default. Logs can include requests to Cloudflare's API, any usage data being collected, and more verbose error logs.
6570

66-
* `FORCE_COLOR` <Type text="string" /> <MetaInfo text="optional" />
71+
- `WRANGLER_LOG_PATH` <Type text="string" /> <MetaInfo text="optional" />
6772

68-
* By setting this to `0`, you can disable Wrangler's colorised output, which makes it easier to read with some terminal setups. For example, `FORCE_COLOR=0`.
73+
- A file or directory path where Wrangler will write debug logs. If the path ends in `.log`, Wrangler will consider this the path to a file where all logs will be written. Otherwise, Wrangler will treat the path as a directory where it will write one or more log files using a timestamp for the filenames.
6974

70-
* `WRANGLER_DOCKER_HOST` <Type text="string" /> <MetaInfo text="optional" />
75+
- `FORCE_COLOR` <Type text="string" /> <MetaInfo text="optional" />
7176

72-
* Defaults to `unix:///var/run/docker.sock`. Set this to the socket path your container engine is listening at if you are using another container tool besides Docker, such as `colima`, or if your Docker engine is configured to listen at a path other than `unix:///var/run/docker.sock`.
73-
You can also set this via `container_engine` config option.
77+
- By setting this to `0`, you can disable Wrangler's colorised output, which makes it easier to read with some terminal setups. For example, `FORCE_COLOR=0`.
7478

79+
- `WRANGLER_DOCKER_HOST` <Type text="string" /> <MetaInfo text="optional" />
7580

81+
- Defaults to `unix:///var/run/docker.sock`. Set this to the socket path your container engine is listening at if you are using another container tool besides Docker, such as `colima`, or if your Docker engine is configured to listen at a path other than `unix:///var/run/docker.sock`.
82+
You can also set this via `container_engine` config option.
7683

7784
## Example `.env` file
7885

@@ -92,8 +99,8 @@ WRANGLER_LOG_PATH=../Desktop/my-logs/my-log-file.log
9299

93100
The following variables are deprecated. Use the new variables listed above to prevent any issues or unwanted messaging.
94101

95-
* `CF_ACCOUNT_ID`
96-
* `CF_API_TOKEN`
97-
* `CF_API_KEY`
98-
* `CF_EMAIL`
99-
* `CF_API_BASE_URL`
102+
- `CF_ACCOUNT_ID`
103+
- `CF_API_TOKEN`
104+
- `CF_API_KEY`
105+
- `CF_EMAIL`
106+
- `CF_API_BASE_URL`

0 commit comments

Comments
 (0)