Skip to content
VaelJS Blog

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"
Since v0.0.0-alpha.0 vjs (V8) vjs-lite (QuickJS)
Cargo feature: node-compat (enabled by default; disable with --no-node-compat)
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;
API Symbols
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function cwd(): string;

Return the current working directory.

Returns
string — Current working directory path string.
Exceptions
  • Error — with code = "EIO" or "EINVAL" if the working directory cannot be queried or is not valid UTF-8.
import { cwd } from "node:process";
console.log(cwd());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function chdir(directory: string): void;

Change the current working directory to directory.

Parameters
NameTypeDescription
directorystringTarget directory path.
Returns
void
Exceptions
  • TypeError — when directory is not a string.
  • Error — with code "ENOENT", "ENOTDIR", "EACCES", "EINVAL", or "EIO".
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function exit(code?: number): never;

Terminate the process synchronously with code.

Uses process.exitCode (default 0) when code is undefined. Never returns.

Parameters
NameTypeDescription
code optionalnumberOptional integer exit status code.
Returns
never
Exceptions
  • TypeError — when code is provided and is not a finite number.
import { exit } from "node:process";
exit(0);
functionSince v0.0.0-alpha.2vjs & vjs-lite
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.

Parameters
NameTypeDescription
callback(...args: TArgs) => voidFunction invoked on the next tick.
...argsTArgsAdditional arguments forwarded to callback.
Returns
void
Exceptions
  • TypeError — when callback is not a function.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function uptime(): number;

Return the number of seconds the current process has been running.

Returns
number — Process uptime in seconds.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function on(
  eventName: string | symbol,
  listener: (...args: any[]) => void,
): ProcessObject;

Register a listener for process event eventName.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener(...args: any[]) => voidCallback invoked when eventName is emitted.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function once(
  eventName: string | symbol,
  listener: (...args: any[]) => void,
): ProcessObject;

Register a one-time listener for process event eventName.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener(...args: any[]) => voidCallback invoked at most once.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function off(
  eventName: string | symbol,
  listener: (...args: any[]) => void,
): ProcessObject;

Remove listener from process event eventName.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener(...args: any[]) => voidListener function to remove.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function emit(eventName: string | symbol, ...args: any[]): boolean;

Synchronously emit process event eventName with args.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
...argsany[]Arguments passed to listeners.
Returns
boolean — true if any listeners ran, otherwise false.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function addListener(
  eventName: string | symbol,
  listener: (...args: any[]) => void,
): ProcessObject;

Alias for on(eventName, listener).

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener(...args: any[]) => voidCallback invoked when eventName is emitted.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function removeListener(
  eventName: string | symbol,
  listener: (...args: any[]) => void,
): ProcessObject;

Alias for off(eventName, listener).

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener(...args: any[]) => voidListener function to remove.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function removeAllListeners(eventName?: string | symbol): ProcessObject;

Remove all listeners, or all listeners for eventName, from process.

Parameters
NameTypeDescription
eventName optionalstring | symbolOptional event name or symbol.
Returns
ProcessObject — The process object for chaining.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function listeners(eventName: string | symbol): Array<(...args: any[]) => void>;

Return a copy of the array of listeners for eventName on process.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
Returns
Array<(...args: any[]) => void> — Array of registered listener functions.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function listenerCount(
  eventName: string | symbol,
  listener?: (...args: any[]) => void,
): number;

Return the number of listeners registered for eventName on process.

Parameters
NameTypeDescription
eventNamestring | symbolEvent name or symbol.
listener optional(...args: any[]) => voidOptional specific listener to count.
Returns
number — Number of matching listeners.
interfaceSince v0.0.0-alpha.0vjs & vjs-lite
export interface HrTime {
  (time?: [number, number]): [number, number];
  bigint(): bigint;
}

High-resolution real-time clock helper (process.hrtime).

Call Signature
(time?: [number, number]): [number, number];

Return [seconds, nanoseconds] tuple relative to an arbitrary time or time.

Parameters
NameTypeDescription
time optional[number, number]Optional previous [seconds, nanoseconds] tuple to compute a diff against.
Returns
[number, number] — Two-element [seconds, nanoseconds] tuple.
Exceptions
  • TypeError — when time is 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]);
Methods
methodSince v0.0.0-alpha.0
bigint(): bigint;

Return current high-resolution time in nanoseconds as a bigint.

Returns
bigint — Monotonic clock reading in nanoseconds.
import { hrtime } from "node:process";
const t0 = hrtime.bigint();
const t1 = hrtime.bigint();
console.log(t1 - t0);
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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.

Properties
PropertyTypeDescriptionSince
fd readonlynumberFile descriptor number (0 for stdin).v0.0.0-alpha.2
isTTY readonly optionalbooleanWhether the stream is connected to an interactive terminal (TTY).v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
setEncoding(encoding: string): this;

Set character encoding for decoded data events.

Parameters
NameTypeDescription
encodingstring—
Returns
this
methodSince v0.0.0-alpha.2
read(size?: number): unknown;

Read buffered data synchronously if available.

Parameters
NameTypeDescription
size optionalnumber—
Returns
unknown
methodSince v0.0.0-alpha.2
pause(): this;

Pause data events.

Returns
this
methodSince v0.0.0-alpha.2
resume(): this;

Resume data events.

Returns
this
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this

ProcessReadableStream.[Symbol.asyncIterator]

Section titled “ProcessReadableStream.[Symbol.asyncIterator]”
methodSince v0.0.0-alpha.2
[Symbol.asyncIterator](): AsyncIterableIterator<any>;

Iterate asynchronously over stdin chunks.

interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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.

Properties
PropertyTypeDescriptionSince
fd readonlynumberFile descriptor number (1 for stdout, 2 for stderr).v0.0.0-alpha.2
isTTY readonly optionalbooleanWhether the stream is connected to an interactive terminal (TTY).v0.0.0-alpha.2
columns readonly optionalnumberTerminal column width when isTTY is true.v0.0.0-alpha.2
rows readonly optionalnumberTerminal row height when isTTY is true.v0.0.0-alpha.2
Methods
methodSince v0.0.0-alpha.2
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.

Overload 1 — write(chunk, callback?)
NameTypeDescription
chunkstring | Uint8Array | ArrayBufferViewString or byte view to write.
callback optional(err?: Error | null) => voidOptional completion callback.
boolean — true if flushed immediately, false under backpressure.
Overload 2 — write(chunk, encoding, callback?)

Write string data with an explicit encoding to the stream.

NameTypeDescription
chunkstringString to write.
encodingstringCharacter encoding.
callback optional(err?: Error | null) => voidOptional completion callback.
boolean — true if flushed immediately, false under backpressure.
methodSince v0.0.0-alpha.2
on(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
once(eventName: string | symbol, listener: (...args: any[]) => void): this;

Register a one-time stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
methodSince v0.0.0-alpha.2
off(eventName: string | symbol, listener: (...args: any[]) => void): this;

Remove a stream event listener.

Parameters
NameTypeDescription
eventNamestring | symbol—
listener(...args: any[]) => void—
Returns
this
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
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".

Properties
PropertyTypeDescriptionSince
argv readonlytypeof argvCommand-line arguments passed to the runtime.v0.0.0-alpha.0
argv0 readonlytypeof argv0Original value of argv[0] passed at startup.v0.0.0-alpha.2
execPath readonlytypeof execPathAbsolute pathname of the executable that started the runtime.v0.0.0-alpha.2
execArgv readonlytypeof execArgvRuntime-specific command-line flags passed before the script path.v0.0.0-alpha.2
cwd typeof cwdReturn the current working directory.v0.0.0-alpha.0
chdir typeof chdirChange the current working directory.v0.0.0-alpha.0
env readonlytypeof envLive environment variable map.v0.0.0-alpha.0
exit typeof exitTerminate the process synchronously.v0.0.0-alpha.0
exitCode number | undefinedExit code used when the process exits normally.v0.0.0-alpha.0
platform readonlytypeof platformOperating system platform identifier.v0.0.0-alpha.0
arch readonlytypeof archCPU architecture identifier.v0.0.0-alpha.0
pid readonlytypeof pidCurrent process ID.v0.0.0-alpha.0
version readonlytypeof versionRuntime Node-compatibility version string.v0.0.0-alpha.0
versions readonlytypeof versionsRuntime component version map.v0.0.0-alpha.0
hrtime readonlytypeof hrtimeHigh-resolution timer function with .bigint().v0.0.0-alpha.0
stdin readonlytypeof stdinStandard input stream.v0.0.0-alpha.2
stdout readonlytypeof stdoutStandard output stream.v0.0.0-alpha.2
stderr readonlytypeof stderrStandard error stream.v0.0.0-alpha.2
nextTick typeof nextTickSchedule a callback on the next-tick queue.v0.0.0-alpha.2
uptime typeof uptimeReturn process uptime in seconds.v0.0.0-alpha.2
on typeof onRegister a process event listener.v0.0.0-alpha.2
once typeof onceRegister a one-time process event listener.v0.0.0-alpha.2
off typeof offRemove a process event listener.v0.0.0-alpha.2
emit typeof emitEmit an event on process.v0.0.0-alpha.2
addListener typeof addListenerAlias for on.v0.0.0-alpha.2
removeListener typeof removeListenerAlias for off.v0.0.0-alpha.2
removeAllListeners typeof removeAllListenersRemove all listeners for an event or all events.v0.0.0-alpha.2
listeners typeof listenersReturn registered listeners for an event.v0.0.0-alpha.2
listenerCount typeof listenerCountReturn listener count for an event.v0.0.0-alpha.2
constSince v0.0.0-alpha.0vjs & vjs-lite
export const argv: readonly string[];

Command-line arguments passed to the runtime.

constSince v0.0.0-alpha.0vjs & vjs-lite
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.

letSince v0.0.0-alpha.0vjs & vjs-lite
export let exitCode: number | undefined;

Exit code to use when the process exits normally.

Setting a non-finite number throws a TypeError.

constSince v0.0.0-alpha.0vjs & vjs-lite
export const platform: string;

Operating system platform identifier (such as "linux", "darwin", or "win32").

constSince v0.0.0-alpha.0vjs & vjs-lite
export const arch: string;

CPU architecture identifier (such as "x64" or "arm64").

constSince v0.0.0-alpha.0vjs & vjs-lite
export const pid: number;

Current process ID.

constSince v0.0.0-alpha.0vjs & vjs-lite
export const version: string;

Runtime Node-compatibility version string (for example "v22.0.0").

constSince v0.0.0-alpha.0vjs & vjs-lite
export const versions: Readonly<Record<string, string>>;

Runtime component version map (includes node and engine keys such as vjs/v8 or vaeljs/quickjs).

constSince v0.0.0-alpha.0vjs & vjs-lite
export const hrtime: HrTime;

High-resolution timer function with .bigint().

constSince v0.0.0-alpha.2vjs & vjs-lite
export const stdin: ProcessReadableStream;

Standard input stream (fd 0).

constSince v0.0.0-alpha.2vjs & vjs-lite
export const stdout: ProcessWritableStream;

Standard output stream (fd 1).

constSince v0.0.0-alpha.2vjs & vjs-lite
export const stderr: ProcessWritableStream;

Standard error stream (fd 2).

constSince v0.0.0-alpha.2vjs & vjs-lite
export const argv0: string;

Original value of argv[0] passed when the runtime started.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const execPath: string;

Absolute pathname of the executable that started the runtime.

constSince v0.0.0-alpha.2vjs & vjs-lite
export const execArgv: readonly string[];

Runtime-specific command-line options passed before the script path.

defaultSince v0.0.0-alpha.0vjs & vjs-lite
const _default: ProcessObject;
export default _default;

Default export object providing the node:process API.