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
Copy file name to clipboardExpand all lines: src/content/docs/workers/runtime-apis/nodejs/process.mdx
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,10 @@ In the Node.js implementation of `process.env`, the `env` object is a copy of th
33
33
Workers have a concept of [environment variables](/workers/configuration/environment-variables/) that are applied on a per-Worker and per-request basis.
34
34
35
35
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
37
37
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.
39
40
40
41
Setting any value on `process.env` will coerce that value into a string.
41
42
@@ -55,7 +56,22 @@ export default {
55
56
};
56
57
```
57
58
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*asprocessfrom'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,
0 commit comments