node:process
Node-compatible process metadata, environment variables, working directory, and exit control.
Available in both vjs and vjs-lite runtimes. Enabled by default unless
--no-node-compat is passed.
import ... from "node:process"
node-compat (enabled by default; disable with --no-node-compat)Example
Section titled “Example”import process, { cwd, env, hrtime, platform } from "node:process";
const start = hrtime.bigint();console.log(platform, cwd(), env.HOME ?? "");const elapsedNs = hrtime.bigint() - start;console.log(`Elapsed ns: ${elapsedNs}`);process.exitCode = 0;cwdv0.0.0-alpha.0chdirv0.0.0-alpha.0directory.exitv0.0.0-alpha.0code.nextTickv0.0.0-alpha.2callback to run on the next-tick queue after the current synchronous turn.uptimev0.0.0-alpha.2onv0.0.0-alpha.2eventName.oncev0.0.0-alpha.2eventName.offv0.0.0-alpha.2listener from process event eventName.emitv0.0.0-alpha.2eventName with args.addListenerv0.0.0-alpha.2on(eventName, listener).removeListenerv0.0.0-alpha.2off(eventName, listener).removeAllListenersv0.0.0-alpha.2eventName, from process.listenersv0.0.0-alpha.2eventName on process.listenerCountv0.0.0-alpha.2eventName on process.HrTimev0.0.0-alpha.0process.hrtime).ProcessReadableStreamv0.0.0-alpha.2process.stdin.ProcessWritableStreamv0.0.0-alpha.2process.stdout and process.stderr.ProcessObjectv0.0.0-alpha.2process object type exported as the default export of "node:process".argvv0.0.0-alpha.0envv0.0.0-alpha.0exitCodev0.0.0-alpha.0platformv0.0.0-alpha.0"linux", "darwin", or "win32").archv0.0.0-alpha.0"x64" or "arm64").pidv0.0.0-alpha.0versionv0.0.0-alpha.0"v22.0.0").versionsv0.0.0-alpha.0node and engine keys such as vjs/v8 or vaeljs/quickjs).hrtimev0.0.0-alpha.0.bigint().stdinv0.0.0-alpha.2fd 0).stdoutv0.0.0-alpha.2fd 1).stderrv0.0.0-alpha.2fd 2).argv0v0.0.0-alpha.2argv[0] passed when the runtime started.execPathv0.0.0-alpha.2execArgvv0.0.0-alpha.2Functions
Section titled “Functions”export function cwd(): string;
Return the current working directory.
string — Current working directory path string.Error— withcode = "EIO"or"EINVAL"if the working directory cannot be queried or is not valid UTF-8.
import { cwd } from "node:process";
console.log(cwd());export function chdir(directory: string): void;
Change the current working directory to directory.
| Name | Type | Description |
|---|---|---|
directory | string | Target directory path. |
voidTypeError— whendirectoryis not a string.Error— withcode"ENOENT","ENOTDIR","EACCES","EINVAL", or"EIO".
export function exit(code?: number): never;
Terminate the process synchronously with code.
Uses process.exitCode (default 0) when code is undefined. Never returns.
| Name | Type | Description |
|---|---|---|
code optional | number | Optional integer exit status code. |
neverTypeError— whencodeis provided and is not a finite number.
import { exit } from "node:process";
exit(0);nextTick
Section titled “nextTick”export function nextTick<TArgs extends any[]>(
callback: (...args: TArgs) => void,
...args: TArgs
): void;
Schedule callback to run on the next-tick queue after the current synchronous turn.
| Name | Type | Description |
|---|---|---|
callback | (...args: TArgs) => void | Function invoked on the next tick. |
...args | TArgs | Additional arguments forwarded to callback. |
voidTypeError— whencallbackis not a function.
uptime
Section titled “uptime”export function uptime(): number;
Return the number of seconds the current process has been running.
number — Process uptime in seconds.export function on(
eventName: string | symbol,
listener: (...args: any[]) => void,
): ProcessObject;
Register a listener for process event eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener | (...args: any[]) => void | Callback invoked when eventName is emitted. |
ProcessObject — The process object for chaining.export function once(
eventName: string | symbol,
listener: (...args: any[]) => void,
): ProcessObject;
Register a one-time listener for process event eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener | (...args: any[]) => void | Callback invoked at most once. |
ProcessObject — The process object for chaining.export function off(
eventName: string | symbol,
listener: (...args: any[]) => void,
): ProcessObject;
Remove listener from process event eventName.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener | (...args: any[]) => void | Listener function to remove. |
ProcessObject — The process object for chaining.export function emit(eventName: string | symbol, ...args: any[]): boolean;
Synchronously emit process event eventName with args.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
...args | any[] | Arguments passed to listeners. |
boolean — true if any listeners ran, otherwise false.addListener
Section titled “addListener”export function addListener(
eventName: string | symbol,
listener: (...args: any[]) => void,
): ProcessObject;
Alias for on(eventName, listener).
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener | (...args: any[]) => void | Callback invoked when eventName is emitted. |
ProcessObject — The process object for chaining.removeListener
Section titled “removeListener”export function removeListener(
eventName: string | symbol,
listener: (...args: any[]) => void,
): ProcessObject;
Alias for off(eventName, listener).
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener | (...args: any[]) => void | Listener function to remove. |
ProcessObject — The process object for chaining.removeAllListeners
Section titled “removeAllListeners”export function removeAllListeners(eventName?: string | symbol): ProcessObject;
Remove all listeners, or all listeners for eventName, from process.
| Name | Type | Description |
|---|---|---|
eventName optional | string | symbol | Optional event name or symbol. |
ProcessObject — The process object for chaining.listeners
Section titled “listeners”export function listeners(eventName: string | symbol): Array<(...args: any[]) => void>;
Return a copy of the array of listeners for eventName on process.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
Array<(...args: any[]) => void> — Array of registered listener functions.listenerCount
Section titled “listenerCount”export function listenerCount(
eventName: string | symbol,
listener?: (...args: any[]) => void,
): number;
Return the number of listeners registered for eventName on process.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | Event name or symbol. |
listener optional | (...args: any[]) => void | Optional specific listener to count. |
number — Number of matching listeners.Interfaces
Section titled “Interfaces”HrTime
Section titled “HrTime”export interface HrTime {
(time?: [number, number]): [number, number];
bigint(): bigint;
}
High-resolution real-time clock helper (process.hrtime).
(time?: [number, number]): [number, number];
Return [seconds, nanoseconds] tuple relative to an arbitrary time or time.
| Name | Type | Description |
|---|---|---|
time optional | [number, number] | Optional previous [seconds, nanoseconds] tuple to compute a diff against. |
[number, number] — Two-element [seconds, nanoseconds] tuple.TypeError— whentimeis supplied and is not a two-element[number, number]array.
import { hrtime } from "node:process";
const start = hrtime();const diff = hrtime(start);console.log(diff[0], diff[1]);HrTime.bigint
Section titled “HrTime.bigint”bigint(): bigint;
Return current high-resolution time in nanoseconds as a bigint.
bigint — Monotonic clock reading in nanoseconds.import { hrtime } from "node:process";
const t0 = hrtime.bigint();const t1 = hrtime.bigint();console.log(t1 - t0);ProcessReadableStream
Section titled “ProcessReadableStream”export interface ProcessReadableStream {
readonly fd: number;
readonly isTTY?: boolean;
setEncoding(encoding: string): this;
read(size?: number): unknown;
pause(): this;
resume(): this;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
[Symbol.asyncIterator](): AsyncIterableIterator<any>;
}
Standard input stream interface exposed as process.stdin.
| Property | Type | Description | Since |
|---|---|---|---|
fd readonly | number | File descriptor number (0 for stdin). | v0.0.0-alpha.2 |
isTTY readonly optional | boolean | Whether the stream is connected to an interactive terminal (TTY). | v0.0.0-alpha.2 |
ProcessReadableStream.setEncoding
Section titled “ProcessReadableStream.setEncoding”setEncoding(encoding: string): this;
Set character encoding for decoded data events.
| Name | Type | Description |
|---|---|---|
encoding | string | — |
thisProcessReadableStream.read
Section titled “ProcessReadableStream.read”read(size?: number): unknown;
Read buffered data synchronously if available.
| Name | Type | Description |
|---|---|---|
size optional | number | — |
unknownProcessReadableStream.pause
Section titled “ProcessReadableStream.pause”pause(): this;
Pause data events.
thisProcessReadableStream.resume
Section titled “ProcessReadableStream.resume”resume(): this;
Resume data events.
thisProcessReadableStream.on
Section titled “ProcessReadableStream.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessReadableStream.once
Section titled “ProcessReadableStream.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessReadableStream.off
Section titled “ProcessReadableStream.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessReadableStream.[Symbol.asyncIterator]
Section titled “ProcessReadableStream.[Symbol.asyncIterator]”[Symbol.asyncIterator](): AsyncIterableIterator<any>;
Iterate asynchronously over stdin chunks.
ProcessWritableStream
Section titled “ProcessWritableStream”export interface ProcessWritableStream {
readonly fd: number;
readonly isTTY?: boolean;
readonly columns?: number;
readonly rows?: number;
write(chunk: string | Uint8Array | ArrayBufferView, callback?: (err?: Error | null) => void): boolean;
write(
chunk: string,
encoding: string,
callback?: (err?: Error | null) => void,
): boolean;
on(eventName: string | symbol, listener: (...args: any[]) => void): this;
once(eventName: string | symbol, listener: (...args: any[]) => void): this;
off(eventName: string | symbol, listener: (...args: any[]) => void): this;
}
Standard output/error stream interface exposed as process.stdout and process.stderr.
| Property | Type | Description | Since |
|---|---|---|---|
fd readonly | number | File descriptor number (1 for stdout, 2 for stderr). | v0.0.0-alpha.2 |
isTTY readonly optional | boolean | Whether the stream is connected to an interactive terminal (TTY). | v0.0.0-alpha.2 |
columns readonly optional | number | Terminal column width when isTTY is true. | v0.0.0-alpha.2 |
rows readonly optional | number | Terminal row height when isTTY is true. | v0.0.0-alpha.2 |
ProcessWritableStream.write
Section titled “ProcessWritableStream.write”write(chunk: string | Uint8Array | ArrayBufferView, callback?: (err?: Error | null) => void): boolean;
write(
chunk: string,
encoding: string,
callback?: (err?: Error | null) => void,
): boolean;
Write string or byte data to the stream.
write(chunk, callback?)| Name | Type | Description |
|---|---|---|
chunk | string | Uint8Array | ArrayBufferView | String or byte view to write. |
callback optional | (err?: Error | null) => void | Optional completion callback. |
boolean — true if flushed immediately, false under backpressure.write(chunk, encoding, callback?)Write string data with an explicit encoding to the stream.
| Name | Type | Description |
|---|---|---|
chunk | string | String to write. |
encoding | string | Character encoding. |
callback optional | (err?: Error | null) => void | Optional completion callback. |
boolean — true if flushed immediately, false under backpressure.ProcessWritableStream.on
Section titled “ProcessWritableStream.on”on(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessWritableStream.once
Section titled “ProcessWritableStream.once”once(eventName: string | symbol, listener: (...args: any[]) => void): this;
Register a one-time stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessWritableStream.off
Section titled “ProcessWritableStream.off”off(eventName: string | symbol, listener: (...args: any[]) => void): this;
Remove a stream event listener.
| Name | Type | Description |
|---|---|---|
eventName | string | symbol | — |
listener | (...args: any[]) => void | — |
thisProcessObject
Section titled “ProcessObject”export interface ProcessObject {
readonly argv: typeof argv;
readonly argv0: typeof argv0;
readonly execPath: typeof execPath;
readonly execArgv: typeof execArgv;
cwd: typeof cwd;
chdir: typeof chdir;
readonly env: typeof env;
exit: typeof exit;
exitCode: number | undefined;
readonly platform: typeof platform;
readonly arch: typeof arch;
readonly pid: typeof pid;
readonly version: typeof version;
readonly versions: typeof versions;
readonly hrtime: typeof hrtime;
readonly stdin: typeof stdin;
readonly stdout: typeof stdout;
readonly stderr: typeof stderr;
nextTick: typeof nextTick;
uptime: typeof uptime;
on: typeof on;
once: typeof once;
off: typeof off;
emit: typeof emit;
addListener: typeof addListener;
removeListener: typeof removeListener;
removeAllListeners: typeof removeAllListeners;
listeners: typeof listeners;
listenerCount: typeof listenerCount;
}
Full process object type exported as the default export of "node:process".
| Property | Type | Description | Since |
|---|---|---|---|
argv readonly | typeof argv | Command-line arguments passed to the runtime. | v0.0.0-alpha.0 |
argv0 readonly | typeof argv0 | Original value of argv[0] passed at startup. | v0.0.0-alpha.2 |
execPath readonly | typeof execPath | Absolute pathname of the executable that started the runtime. | v0.0.0-alpha.2 |
execArgv readonly | typeof execArgv | Runtime-specific command-line flags passed before the script path. | v0.0.0-alpha.2 |
cwd | typeof cwd | Return the current working directory. | v0.0.0-alpha.0 |
chdir | typeof chdir | Change the current working directory. | v0.0.0-alpha.0 |
env readonly | typeof env | Live environment variable map. | v0.0.0-alpha.0 |
exit | typeof exit | Terminate the process synchronously. | v0.0.0-alpha.0 |
exitCode | number | undefined | Exit code used when the process exits normally. | v0.0.0-alpha.0 |
platform readonly | typeof platform | Operating system platform identifier. | v0.0.0-alpha.0 |
arch readonly | typeof arch | CPU architecture identifier. | v0.0.0-alpha.0 |
pid readonly | typeof pid | Current process ID. | v0.0.0-alpha.0 |
version readonly | typeof version | Runtime Node-compatibility version string. | v0.0.0-alpha.0 |
versions readonly | typeof versions | Runtime component version map. | v0.0.0-alpha.0 |
hrtime readonly | typeof hrtime | High-resolution timer function with .bigint(). | v0.0.0-alpha.0 |
stdin readonly | typeof stdin | Standard input stream. | v0.0.0-alpha.2 |
stdout readonly | typeof stdout | Standard output stream. | v0.0.0-alpha.2 |
stderr readonly | typeof stderr | Standard error stream. | v0.0.0-alpha.2 |
nextTick | typeof nextTick | Schedule a callback on the next-tick queue. | v0.0.0-alpha.2 |
uptime | typeof uptime | Return process uptime in seconds. | v0.0.0-alpha.2 |
on | typeof on | Register a process event listener. | v0.0.0-alpha.2 |
once | typeof once | Register a one-time process event listener. | v0.0.0-alpha.2 |
off | typeof off | Remove a process event listener. | v0.0.0-alpha.2 |
emit | typeof emit | Emit an event on process. | v0.0.0-alpha.2 |
addListener | typeof addListener | Alias for on. | v0.0.0-alpha.2 |
removeListener | typeof removeListener | Alias for off. | v0.0.0-alpha.2 |
removeAllListeners | typeof removeAllListeners | Remove all listeners for an event or all events. | v0.0.0-alpha.2 |
listeners | typeof listeners | Return registered listeners for an event. | v0.0.0-alpha.2 |
listenerCount | typeof listenerCount | Return listener count for an event. | v0.0.0-alpha.2 |
Constants
Section titled “Constants”export const argv: readonly string[];
Command-line arguments passed to the runtime.
export const env: Record<string, string | undefined>;
Live environment variable map.
Supports reading, setting (values are coerced to strings), checking with
in, enumerating keys, and deleting entries within the runtime context.
exitCode
Section titled “exitCode”export let exitCode: number | undefined;
Exit code to use when the process exits normally.
Setting a non-finite number throws a TypeError.
platform
Section titled “platform”export const platform: string;
Operating system platform identifier (such as "linux", "darwin", or "win32").
export const arch: string;
CPU architecture identifier (such as "x64" or "arm64").
export const pid: number;
Current process ID.
version
Section titled “version”export const version: string;
Runtime Node-compatibility version string (for example "v22.0.0").
versions
Section titled “versions”export const versions: Readonly<Record<string, string>>;
Runtime component version map (includes node and engine keys such as vjs/v8 or vaeljs/quickjs).
hrtime
Section titled “hrtime”export const hrtime: HrTime;
High-resolution timer function with .bigint().
export const stdin: ProcessReadableStream;
Standard input stream (fd 0).
stdout
Section titled “stdout”export const stdout: ProcessWritableStream;
Standard output stream (fd 1).
stderr
Section titled “stderr”export const stderr: ProcessWritableStream;
Standard error stream (fd 2).
export const argv0: string;
Original value of argv[0] passed when the runtime started.
execPath
Section titled “execPath”export const execPath: string;
Absolute pathname of the executable that started the runtime.
execArgv
Section titled “execArgv”export const execArgv: readonly string[];
Runtime-specific command-line options passed before the script path.
Default Export
Section titled “Default Export”default export
Section titled “default export”const _default: ProcessObject;
export default _default;
Default export object providing the node:process API.
