-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Document the process.env handling and compat flags #19187
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
base: production
Are you sure you want to change the base?
Conversation
Co-authored-by: hyperlint-ai[bot] <154288675+hyperlint-ai[bot]@users.noreply.github.com>
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added inline comments.
It would be great to add details to https://developers.cloudflare.com/workers/configuration/secrets/ -> mention the flag and process.env
Thanks
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
Co-authored-by: Victor Berchet <[email protected]>
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
I think the doc should mention when this flag will be active by default with |
@@ -48,7 +56,11 @@ export default { | |||
}; | |||
``` | |||
|
|||
It is strongly recommended that you *do not* replace the entire `process.env` object with the request `env` object. Doing so will cause you to lose any environment variables that were set previously and will cause unexpected behavior for other Workers running in the same isolate. Specifically, it would cause inconsistency with the `process.env` object when accessed via named imports. | |||
It is strongly recommended that you *do not* replace the entire `process.env` object with | |||
the request `env` object. Doing so will cause you to lose any environment variables that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe expland "the cloudflare env
object + passed the fetch handler, imported from cloudflare:workers
or retrieved from an entry point"
the request `env` object. Doing so will cause you to lose any environment variables that | |
the cloudflare `env` object. Doing so will cause you to lose any environment variables that |
Co-authored-by: Victor Berchet <[email protected]>
Howdy and thanks for contributing to our repo. The Cloudflare team reviews new, external PRs within two (2) weeks. If it's been two weeks or longer without any movement, please tag the PR Assignees in a comment. We review internal PRs within 1 week. If it's something urgent or has been sitting without a comment, start a thread in the Developer Docs space internally. PR Change SummaryDocumented the handling of process.env and compatibility flags for Node.js in the Workers documentation.
Modified Files
Added Files
How can I customize these reviews?Check out the Hyperlint AI Reviewer docs for more information on how to customize the review. If you just want to ignore it on this PR, you can add the Note specifically for link checks, we only check the first 30 links in a file and we cache the results for several hours (for instance, if you just added a page, you might experience this). Our recommendation is to add |
Co-authored-by: Brendan Irvine-Broque <[email protected]>
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
Co-authored-by: Victor Berchet <[email protected]>
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
src/content/docs/workers/configuration/environment-variables.mdx
Outdated
Show resolved
Hide resolved
list: never | ||
|
||
name: "Populate process.env from environment variables" | ||
sort_date: "2025-01-31" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sort_date
is usually the same as enable_date
Is there any reason to have a difference here?
sort_date: "2025-01-31" | |
sort_date: "2025-04-01" |
disable_flag: "nodejs_compat_do_not_populate_process_env" | ||
--- | ||
|
||
When the `nodejs_compat_populate_process_env` compatibility flag is used in conjunction with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that this also depends on disallow_importable_env
in the latest impl.
@@ -104,6 +104,47 @@ Select the **Secret** type if your environment variable is a [secret](/workers/c | |||
|
|||
<Render file="env_and_secrets" /> | |||
|
|||
## Environment variables and Node.js compatibility | |||
|
|||
When you enable both the [`nodejs_compat`](/workers/runtime-apis/nodejs/) and |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as previously
|
||
Text variable values are exposed directly. | ||
|
||
JSON variable values that evaluate to string values are exposed as the parsed value. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember that there were changes wrt .toJson()
, does the description here need to be updated.
The values of `process.env.FOO` and `process.env.BAR` will each be the | ||
JavaScript string `"abc"`. | ||
|
||
The value of `process.env.BAZ` will be the JSON-encoded string `"{ "a": 123 }"`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The value of `process.env.BAZ` will be the JSON-encoded string `"{ "a": 123 }"`. | |
The value of `process.env.BAZ` will be the JSON-encoded string `"{ \"a\": 123 }"`. |
Workers do have a concept of [environment variables](/workers/configuration/environment-variables/) that are applied on a per-Worker and per-request basis. These are not accessible automatically via the `process.env` API. It is possible to manually copy these values into `process.env` if you need to. Be aware, however, that setting any value on `process.env` will coerce that value into a string. | ||
Workers have a concept of [environment variables](/workers/configuration/environment-variables/) that are applied on a per-Worker and per-request basis. | ||
|
||
By default, these are not accessible automatically via the `process.env` API. It is |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By default, these are not accessible automatically via the `process.env` API. It is | |
By default, these are not accessible via the `process.env` API. It is |
|
||
By default, these are not accessible automatically via the `process.env` API. It is | ||
possible to have environment variables and secrets automatically populated into `process.env` using | ||
the `nodejs_compat_populate_process_env` compatibility flag. It is also possible to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, does this depend on the disallow_importable_env
flag?
Co-authored-by: Brendan Irvine-Broque <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to:
- handle all of the comments - meaning they don't have to be accepted but at least resolved
- describe the interactions with disallow_importable_env
I would love to see some documentation for disallow_importable_env
it might be in the current PR as they are closely related. If not it would be nice to have a tracking issue and make sure this gets documented.
Thanks!
Refs: cloudflare/workerd#3311
Summary
Screenshots (optional)
Documentation checklist