Skip to content

Commit 90b0399

Browse files
jasnellvicb
andauthored
Apply suggestions from code review
Co-authored-by: Victor Berchet <[email protected]>
1 parent 5c71b9d commit 90b0399

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/content/docs/workers/configuration/environment-variables.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ JSON-encoded string and you *want* to be able to parse it as JSON within your
135135
application (e.g. `JSON.parse(process.env.BAR)`) then the value will need to
136136
be "double encoded", for instance `'"\\"abc\\""'`.
137137

138+
:::note
138139
Note also that because secrets are a form of environment variable within the runtime,
139140
secrets are also exposed via `process.env`.
140141

src/content/docs/workers/runtime-apis/nodejs/process.mdx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@ In the Node.js implementation of `process.env`, the `env` object is a copy of th
3333
Workers have a concept of [environment variables](/workers/configuration/environment-variables/) that are applied on a per-Worker and per-request basis.
3434

3535
By default, these are not accessible automatically via the `process.env` API. It is
36-
possible to have environment variables automatically populated into `process.env` using
36+
possible to have environment variables and secrets automatically populated into `process.env` using
3737
the `nodejs_compat_populate_process_env` compatibility flag. It is also possible to
38-
manually copy these values into `process.env` if necessary.
38+
manually copy these values into `process.env` if necessary -- but only within the context of
39+
a request.
3940

4041
Setting any value on `process.env` will coerce that value into a string.
4142

@@ -55,7 +56,22 @@ export default {
5556
};
5657
```
5758
58-
Refer to the [environment variables](/workers/configuration/environment-variables/)
59+
It is strongly recommended that you *do not* replace the entire `process.env` object with
60+
the request `env` object. Doing so will cause you to lose any environment variables that
61+
were set previously and will cause unexpected behavior for other Workers running in the
62+
same isolate. Specifically, it would cause inconsistency with the `process.env` object when
63+
accessed via named imports.
64+
65+
```js
66+
import * as process from 'node:process';
67+
import { env } from 'node:process';
68+
69+
process.env === env; // true! they are the same object
70+
process.env = {}; // replace the object! Do not do this!
71+
process.env === env; // false! they are no longer the same object
72+
73+
// From this point forward, any changes to process.env will not be reflected in env,
74+
// and vice versa!
5975
documentation for more detail.
6076

6177
## `process.nextTick()`

0 commit comments

Comments
 (0)