-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Document the new .env support for local development #23837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
a1370e2
Document the new .env support for local development
petebacondarwin 5db8688
fixup! Document the new .env support for local development
petebacondarwin f4bb9b5
fixup! Document the new .env support for local development
petebacondarwin 6c1bbea
update development-testing/environment-variables page
petebacondarwin 383ff79
fix caution box title
petebacondarwin 9ed8dfb
update vite-plugin page
petebacondarwin 382757c
update system environment variables page
petebacondarwin d83e2bf
clarify env vars that control handling
petebacondarwin e42f3fd
merge conflict
kodster28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,45 +16,66 @@ System environment variables are local environment variables that can change Wra | |
| 3. Set the values in your shell environment. For example, if you are using Z shell, adding `export CLOUDFLARE_API_TOKEN=...` to your `~/.zshrc` file will set this token as part of your shell configuration. | ||
|
|
||
| :::note | ||
|
|
||
| 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. | ||
| ::: | ||
|
|
||
| :::note | ||
| 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. | ||
|
|
||
| For example, if you set `API_HOST="localhost:3000"` in your `.env` file, you can access it in your Worker like this: | ||
|
|
||
| ```js | ||
| const apiHost = env.API_HOST; | ||
| ``` | ||
|
|
||
| See the [Environment variables and secrets](/workers/development-testing/environment-variables/) page for more information on how to use `.env` files in local development. | ||
| ::: | ||
|
|
||
| ## Supported environment variables | ||
|
|
||
| Wrangler supports the following environment variables: | ||
|
|
||
| - `CLOUDFLARE_ACCOUNT_ID` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - The [account ID](/fundamentals/account/find-account-and-zone-ids/) for the Workers related account. | ||
|
|
||
| - `CLOUDFLARE_API_TOKEN` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - 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. | ||
|
|
||
| - `CLOUDFLARE_API_KEY` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - The API key for your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_EMAIL=`. | ||
|
|
||
| - `CLOUDFLARE_EMAIL` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - The email address associated with your Cloudflare account, usually used for older authentication method with `CLOUDFLARE_API_KEY=`. | ||
|
|
||
| - `WRANGLER_SEND_METRICS` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - 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). | ||
|
|
||
| - `WRANGLER_HYPERDRIVE_LOCAL_CONNECTION_STRING_<BINDING_NAME>`<Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - 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. | ||
|
|
||
| - `CLOUDFLARE_API_BASE_URL` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - The default value is `"https://api.cloudflare.com/client/v4"`. | ||
|
|
||
| - `WRANGLER_LOG` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - 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. | ||
|
|
||
| - `WRANGLER_LOG_PATH` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - 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. | ||
|
|
||
| - `FORCE_COLOR` <Type text="string" /> <MetaInfo text="optional" /> | ||
| - 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`. | ||
|
|
||
| * `WRANGLER_HTTPS_KEY_PATH` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
| - Path to a custom HTTPS certificate key when running `wrangler dev`, to be used with `WRANGLER_HTTPS_CERT_PATH`. | ||
|
|
||
| * `WRANGLER_HTTPS_CERT_PATH` <Type text="string" /> <MetaInfo text="optional" /> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.