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
When enabled, the `enable_nodejs_process_v2` flag along with the [`nodejs_compat`](/workers/runtime-apis/nodejs/) compat flag
10
+
ensures a comprehensive Node.js-compatible `process` implementation, updating from the previous minimal process implementation
11
+
that only provided the limited `nextTick`, `env`, `exit`, `getBuiltinModule`, `platform` and `features` properties.
12
+
13
+
To continue using the previous minimal implementation after the compat date, set the `disable_nodejs_process_v2` flag instead.
14
+
15
+
Most Node.js-supported process properties are implemented where possible, with undefined exports for unsupported features. See the Wo[process documentation](/workers/runtime-apis/nodejs/process/) for Workers-specific implementation details.
The [`process`](https://nodejs.org/dist/latest-v19.x/docs/api/process.html) module in Node.js provides a number of useful APIs related to the current process. Within a serverless environment like Workers, most of these APIs are not relevant or meaningful, but some are useful for cross-runtime compatibility. Within Workers, the following APIs are available:
10
+
The [`process`](https://nodejs.org/dist/latest-v22.x/docs/api/process.html) module in Node.js provides a number of useful APIs related to the current process.
11
11
12
-
```js
13
-
import { env, nextTick } from"node:process";
12
+
Initially Workers only supported `nextTick`, `env`, `exit`, `getBuiltinModule`, `platform` and `features` on process,
13
+
which was then updated with the [`enable_nodejs_process_v2`](/workers/configuration/compatibility-flags/#enable-process-v2-implementation) flag to include most Node.js process features.
14
14
15
-
env["FOO"] ="bar";
16
-
console.log(env["FOO"]); // Prints: bar
15
+
Refer to the [Node.js documentation for `process`](https://nodejs.org/dist/latest-v22.x/docs/api/process.html) for more information.
17
16
18
-
nextTick(() => {
19
-
console.log("next tick");
20
-
});
21
-
```
17
+
Workers-specific implementation details apply when adapting Node.js support for a serverless environment, which are described in more detail below.
22
18
23
19
## `process.env`
24
20
@@ -77,5 +73,66 @@ process.env === env; // false! they are no longer the same object
77
73
78
74
The Workers implementation of`process.nextTick()` is a wrapper for the standard Web Platform API [`queueMicrotask()`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/queueMicrotask).
79
75
80
-
Refer to the [Node.js documentation for`process`](https://nodejs.org/dist/latest-v19.x/docs/api/process.html) for more information.
76
+
```js
77
+
import { env, nextTick } from "node:process";
78
+
79
+
env["FOO"] = "bar";
80
+
console.log(env["FOO"]); // Prints: bar
81
+
82
+
nextTick(() => {
83
+
console.log("next tick");
84
+
});
85
+
```
86
+
87
+
## Stdio
88
+
89
+
`process.stdout`, `process.stderr` and `process.stdin` are supported as streams. `stdin` is treated as an empty readable stream.
90
+
`stdout` and `stderr` are treated as non-TTY writable streams, with line buffering when integrating with inspector and structured
91
+
logging output.
92
+
93
+
The line buffer is cleared by either a newline or the next microtask, so that synchronous writes without newline characters will always
94
+
remain contiguous on the same line.
95
+
96
+
For example, the following will behave as if calling `console.log('one')` followed by `console.log('two')`:
97
+
98
+
```js
99
+
// equivalent to `console.log('one');`
100
+
process.stdout.write('o');
101
+
process.stdout.write('n');
102
+
process.stdout.write('e');
103
+
await 0;
104
+
// equivalent to `console.log('two')`
105
+
process.stdout.write('t');
106
+
process.stdout.write('w');
107
+
process.stdout.write('o');
108
+
process.stdout.write('\n');
109
+
// equivalent to `console.log('')`
110
+
process.stdout.write('\n');
111
+
```
112
+
113
+
## Filesystem
114
+
115
+
`process.cwd()` is initialized to `/bundle`.
116
+
117
+
`process.chdir()` may be used to alter the current working directory, and is respected by FS operations when using `enable_nodejs_fs_module`.
118
+
119
+
## Hrtime
120
+
121
+
`process.hrtime` is now available, but currently provides an unaccurate timer for compatiblity only.
122
+
123
+
## Unsupported Features
124
+
125
+
The following process properties are currently entirely unsupported and return`undefined`:`binding`, `channel`, `connected`, `debugPort`, `dlopen`,
0 commit comments