process
The process
↗ module in Node.js provides a number of useful APIs related to the current process.
Initially Workers only supported nextTick
, env
, exit
, getBuiltinModule
, platform
and features
on process,
which was then updated with the enable_nodejs_process_v2
flag to include most Node.js process features.
Refer to the Node.js documentation for process
↗ for more information.
Workers-specific implementation details apply when adapting Node.js process support for a serverless environment, which are described in more detail below.
In the Node.js implementation of process.env
, the env
object is a copy of the environment variables at the time the process was started. In the Workers implementation, there is no process-level environment, so by default env
is an empty object. You can still set and get values from env
, and those will be globally persistent for all Workers running in the same isolate and context (for example, the same Workers entry point).
When Node.js compatibility is turned on and the nodejs_compat_populate_process_env
compatibility flag is set, process.env
will contain any environment variables,
secrets, or version metadata metadata that has been configured on your Worker.
Workers have a concept of environment variables that are applied on a per-Worker and per-request basis.
By default, these are not accessible via the process.env
API.
To automatically populate environment variables and secrets on process.env
, enable
the nodejs_compat_populate_process_env
compatibility flag and disable the disallow_importable_env
compatibility flag.
It is also possible to manually copy these values into process.env
if
necessary -- but only within the context of a request.
Setting any value on process.env
will coerce that value into a string.
import * as process from "node:process";
export default { fetch(req, env) { // Set process.env.FOO to the value of env.FOO if process.env.FOO is not already set // and env.FOO is a string. process.env.FOO ??= (() => { if (typeof env.FOO === "string") { return env.FOO; } })(); },};
It is strongly recommended that you do not replace the entire process.env
object with
the cloudflare 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.
import * as process from 'node:process';import { env } from 'node:process';
process.env === env; // true! they are the same objectprocess.env = {}; // replace the object! Do not do this!process.env === env; // false! they are no longer the same object
// From this point forward, any changes to process.env will not be reflected in env,// and vice versa!
## `process.nextTick()`
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).
```jsimport { env, nextTick } from "node:process";
env["FOO"] = "bar";console.log(env["FOO"]); // Prints: bar
nextTick(() => { console.log("next tick");});
process.stdout
↗, process.stderr
↗ and process.stdin
↗ are supported as streams. stdin
is treated as an empty readable stream.
stdout
and stderr
are non-TTY writable streams, which output to normal logging output only with stdout:
and stderr:
prefixing.
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.
This ensures compatibility with inspector and structured logging outputs.
process.cwd()
↗ is the current workding directory, used as the default path for all filesystem operations, and is initialized to /bundle
.
process.chdir()
↗ allows modifying the cwd
and is respected by FS operations when using enable_nodejs_fs_module
.
While process.hrtime
↗ high-resolution timer is available, it provides an inaccurate timer for compatibility only.
The following process
properties are currently entirely unsupported and return undefined
: binding
, channel
, connected
, debugPort
, dlopen
,
exitCode
, finalization
, getActiveResourcesInfo
, hasUncaughtExceptionCaptureCallback
, kill
, memoryUsage
, noDeprecation
, permission
,
ref
, release
, report
, resourceUsage
, send
, setUncaughtExceptionCaptureCallback
, sourceMapsEnabled
, threadCpuUsage
,
throwDeprecation
, traceDeprecation
, unref
.
These unimplemented features may be feature-detected via conditional gating patterns like:
if (process.dlopen) { // use dlopen when available}
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-