Skip to content

Commit 5e215fc

Browse files
guybedfordvicb
andauthored
document nodejs_process_v2 compat flag (#24916)
* document nodejs_process_v2 compat flag * pr feedback * remove logging example * Apply suggestion from @vicb * Apply suggestion from @vicb * Update title * update stdio doc --------- Co-authored-by: Victor Berchet <[email protected]>
1 parent 7ceb9be commit 5e215fc

File tree

3 files changed

+68
-15
lines changed

3 files changed

+68
-15
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
name: "Enable `process` v2 implementation"
3+
sort_date: "2025-09-15"
4+
enable_date: "2025-09-15"
5+
enable_flag: "enable_nodejs_process_v2"
6+
disable_flag: "disable_nodejs_process_v2"
7+
---
8+
9+
When enabled after 2025-09-15, 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 [process documentation](/workers/runtime-apis/nodejs/process/) for Workers-specific implementation details.

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@ The runtime APIs from Node.js listed below as "🟢 supported" are currently nat
4747
| Events | 🟢 supported |
4848
| File system | ⚪ coming soon |
4949
| Globals | 🟢 supported |
50-
| HTTP | 🟢 supported |
50+
| [HTTP](/workers/runtime-apis/nodejs/http/) | 🟢 supported |
5151
| HTTP/2 | ⚪ not yet supported |
52-
| HTTPS | 🟢 supported |
52+
| [HTTPS](/workers/runtime-apis/nodejs/https/) | 🟢 supported |
5353
| Inspector | 🟢 supported via [Chrome Dev Tools integration](/workers/observability/dev-tools/) |
5454
| [Net](/workers/runtime-apis/nodejs/net/) | 🟢 supported |
5555
| OS | ⚪ not yet supported |
5656
| [Path](/workers/runtime-apis/nodejs/path/) | 🟢 supported |
5757
| Performance hooks | 🟡 partially supported |
58-
| Process | 🟢 supported |
58+
| [Process](/workers/runtime-apis/nodejs/process/) | 🟢 supported |
5959
| Query strings | 🟢 supported |
60-
| Stream | 🟢 supported |
60+
| [Stream](/workers/runtime-apis/nodejs/streams/) | 🟢 supported |
6161
| [String decoder](/workers/runtime-apis/nodejs/string-decoder/) | 🟢 supported |
6262
| [Timers](/workers/runtime-apis/nodejs/timers/) | 🟢 supported |
63-
| TLS/SSL | 🟡 partially supported |
63+
| [TLS/SSL](/workers/runtime-apis/nodejs/tls/) | 🟡 partially supported |
6464
| UDP/datagram | ⚪ not yet supported |
6565
| [URL](/workers/runtime-apis/nodejs/url/) | 🟢 supported |
6666
| [Utilities](/workers/runtime-apis/nodejs/util/) | 🟢 supported |

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

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,14 @@ import { Render } from "~/components";
77

88
<Render file="nodejs-compat-howto" product="workers" />
99

10-
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/docs/latest/api/process.html) module in Node.js provides a number of useful APIs related to the current process.
1111

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.
1414

15-
env["FOO"] = "bar";
16-
console.log(env["FOO"]); // Prints: bar
15+
Refer to the [Node.js documentation for `process`](https://nodejs.org/docs/latest/api/process.html) for more information.
1716

18-
nextTick(() => {
19-
console.log("next tick");
20-
});
21-
```
17+
Workers-specific implementation details apply when adapting Node.js process support for a serverless environment, which are described in more detail below.
2218

2319
## `process.env`
2420

@@ -77,5 +73,47 @@ process.env === env; // false! they are no longer the same object
7773

7874
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).
7975

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`](https://nodejs.org/docs/latest/api/process.html#processstdout), [`process.stderr`](https://nodejs.org/docs/latest/api/process.html#processstderr) and [`process.stdin`](https://nodejs.org/docs/latest/api/process.html#processstdin) are supported as streams. `stdin` is treated as an empty readable stream.
90+
`stdout` and `stderr` are non-TTY writable streams, which output to normal logging output only with `stdout: ` and `stderr: ` prefixing.
91+
92+
The line buffer works by storing writes to stdout or stderr until either a newline character `\n` is encountered or until the next microtask, when the log is then flushed to the output.
93+
94+
This ensures compatibility with inspector and structured logging outputs.
95+
96+
## Current Working Directory
97+
98+
[`process.cwd()`](https://nodejs.org/docs/latest/api/process.html#processcwd) is the _current workding directory_, used as the default path for all filesystem operations, and is initialized to `/bundle`.
99+
100+
[`process.chdir()`](https://nodejs.org/docs/latest/api/process.html#processchdirdirectory) allows modifying the `cwd` and is respected by FS operations when using `enable_nodejs_fs_module`.
101+
102+
## Hrtime
103+
104+
While [`process.hrtime`](https://nodejs.org/docs/latest/api/process.html#processhrtimetime) high-resolution timer is available, it provides an inaccurate timer for compatibility only.
105+
106+
## Unsupported Features
107+
108+
The following `process` properties are currently entirely unsupported and return `undefined`: `binding`, `channel`, `connected`, `debugPort`, `dlopen`,
109+
`exitCode`, `finalization`, `getActiveResourcesInfo`, `hasUncaughtExceptionCaptureCallback`, `kill`, `memoryUsage`, `noDeprecation`, `permission`,
110+
`ref`, `release`, `report`, `resourceUsage`, `send`, `setUncaughtExceptionCaptureCallback`, `sourceMapsEnabled`, `threadCpuUsage`,
111+
`throwDeprecation`, `traceDeprecation`, `unref`.
112+
113+
These unimplemented features may be feature-detected via conditional gating patterns like:
114+
115+
```js
116+
if (process.dlopen) {
117+
// use dlopen when available
118+
}
81119
```

0 commit comments

Comments
 (0)