Skip to content
VaelJS Blog

node:os

Node-compatible operating system metadata utilities.

Available in both vjs and vjs-lite runtimes. Enabled by default unless --no-node-compat is passed.

import ... from "node:os"
Since v0.0.0-alpha.0 vjs (V8) vjs-lite (QuickJS)
Cargo feature: node-compat (enabled by default; disable with --no-node-compat)
import { arch, cpus, homedir, hostname, platform, tmpdir } from "node:os";
console.log(platform(), arch(), cpus().length);
console.log(hostname(), homedir(), tmpdir());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function platform(): string;

Return the operating system platform identifier.

Returns
string — Node-compatible platform string such as "linux", "darwin", or "win32".
import { platform } from "node:os";
console.log(platform());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function arch(): string;

Return the operating system CPU architecture identifier.

Returns
string — Node-compatible architecture string such as "x64" or "arm64".
import { arch } from "node:os";
console.log(arch());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function homedir(): string;

Return the current user’s home directory path.

Returns
string — Path string of the current user's home directory.
Exceptions
  • Error — with code = "ERR_UNAVAILABLE" or "EINVAL" if the home directory cannot be determined or is not valid UTF-8.
import { homedir } from "node:os";
console.log(homedir());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function tmpdir(): string;

Return the operating system’s default directory for temporary files.

Returns
string — Path string of the system temporary directory.
Exceptions
  • Error — with code = "EINVAL" if the temporary directory path is not valid UTF-8.
import { tmpdir } from "node:os";
console.log(tmpdir());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function hostname(): string;

Return the host name of the operating system.

Returns
string — Hostname string of the machine.
Exceptions
  • Error — with code = "ERR_UNAVAILABLE" or "EINVAL" if querying the hostname fails or returns invalid UTF-8.
import { hostname } from "node:os";
console.log(hostname());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function cpus(): CpuInfo[];

Return an array of objects containing information about each logical CPU core.

Returns
CpuInfo[] — Array of CpuInfo descriptors matching the host logical CPU count.
import { cpus } from "node:os";
console.log(`Logical cores: ${cpus().length}`);
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function endianness(): "BE" | "LE";

Return the CPU endianness ("BE" or "LE").

Returns
"BE" | "LE" — "BE" for big-endian or "LE" for little-endian architectures.
import { endianness } from "node:os";
console.log(endianness());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function type(): string;

Return the operating system name.

Returns
string — OS name such as "Linux", "Darwin", or "Windows_NT".
import { type } from "node:os";
console.log(type());
functionSince v0.0.0-alpha.0vjs & vjs-lite
export function machine(): string;

Return the machine type string.

Returns
string — Machine hardware identifier such as "x86_64" or "arm64".
import { machine } from "node:os";
console.log(machine());
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function availableParallelism(): number;

Return an estimate of the default amount of parallelism a program should use.

Returns
number — Positive integer count of available parallel execution units.
functionSince v0.0.0-alpha.2vjs & vjs-lite
export function release(): string;

Return the operating system release string.

Returns
string — OS release version string (for example "6.8.0" or "23.4.0").
interfaceSince v0.0.0-alpha.0vjs & vjs-lite
export interface CpuInfo {
  model: string;
  speed: number;
  times: {
      /**
       * Milliseconds spent in user mode.
       *
       * @since 0.0.0-alpha.0
       */
      user: number;
      /**
       * Milliseconds spent in nice mode.
       *
       * @since 0.0.0-alpha.0
       */
      nice: number;
      /**
       * Milliseconds spent in system (kernel) mode.
       *
       * @since 0.0.0-alpha.0
       */
      sys: number;
      /**
       * Milliseconds spent in idle mode.
       *
       * @since 0.0.0-alpha.0
       */
      idle: number;
      /**
       * Milliseconds spent servicing hardware interrupts.
       *
       * @since 0.0.0-alpha.0
       */
      irq: number;
    };
}

CPU core descriptor returned in the array from cpus().

Properties
PropertyTypeDescriptionSince
model stringCPU model string (currently "unknown" in vaeljs).v0.0.0-alpha.0
speed numberCPU clock speed in MHz (currently 0 in vaeljs).v0.0.0-alpha.0
times { /** * Milliseconds spent in user mode. * * @since 0.0.0-alpha.0 */ user: number; /** * Milliseconds spent in nice mode. * * @since 0.0.0-alpha.0 */ nice: number; /** * Milliseconds spent in system (kernel) mode. * * @since 0.0.0-alpha.0 */ sys: number; /** * Milliseconds spent in idle mode. * * @since 0.0.0-alpha.0 */ idle: number; /** * Milliseconds spent servicing hardware interrupts. * * @since 0.0.0-alpha.0 */ irq: number; }Cumulative CPU time breakdown in milliseconds (zero-initialized in vaeljs).v0.0.0-alpha.0
interfaceSince v0.0.0-alpha.2vjs & vjs-lite
export interface OsConstants {
  readonly signals: Readonly<Record<string, number>>;
  readonly errno: Readonly<Record<string, number>>;
  readonly priority: Readonly<Record<string, number>>;
  readonly dlopen: Readonly<Record<string, number>>;
  readonly UV_UDP_REUSEADDR: number;
}

Operating system constants exposed on os.constants.

Properties
PropertyTypeDescriptionSince
signals readonlyReadonly<Record<string, number>>POSIX/platform signal numbers (SIGINT, SIGTERM, etc.).v0.0.0-alpha.2
errno readonlyReadonly<Record<string, number>>POSIX/platform errno error codes (ENOENT, EACCES, etc.).v0.0.0-alpha.2
priority readonlyReadonly<Record<string, number>>Process scheduling priority constants (PRIORITY_LOW, PRIORITY_NORMAL, etc.).v0.0.0-alpha.2
dlopen readonlyReadonly<Record<string, number>>Dynamic linker flags (RTLD_LAZY, RTLD_NOW, etc.).v0.0.0-alpha.2
UV_UDP_REUSEADDR readonlynumberSocket address reuse constant (UV_UDP_REUSEADDR).v0.0.0-alpha.2
constSince v0.0.0-alpha.0vjs & vjs-lite
export const EOL: "\n" | "\r\n";

Operating system end-of-line marker ("\n" or "\r\n").

constSince v0.0.0-alpha.2vjs & vjs-lite
export const devNull: "/dev/null" | "\\\\.\\nul";

Platform-specific path to the null device ("/dev/null" on POSIX, "\\\\.\\nul" on Windows).

constSince v0.0.0-alpha.2vjs & vjs-lite
export const constants: OsConstants;

Operating system signal, errno, priority, and dlopen constants.

defaultSince v0.0.0-alpha.0vjs & vjs-lite
const _default: {
  /** Return the operating system platform identifier. @since 0.0.0-alpha.0 */
  platform: typeof platform;
  /** Return the operating system CPU architecture identifier. @since 0.0.0-alpha.0 */
  arch: typeof arch;
  /** Operating system end-of-line marker (`"\n"` or `"\r\n"`). @since 0.0.0-alpha.0 */
  EOL: typeof EOL;
  /** Return the current user's home directory path. @since 0.0.0-alpha.0 */
  homedir: typeof homedir;
  /** Return the system temporary directory path. @since 0.0.0-alpha.0 */
  tmpdir: typeof tmpdir;
  /** Return the operating system host name. @since 0.0.0-alpha.0 */
  hostname: typeof hostname;
  /** Return an array of logical CPU core descriptors. @since 0.0.0-alpha.0 */
  cpus: typeof cpus;
  /** Return the CPU endianness (`"BE"` or `"LE"`). @since 0.0.0-alpha.0 */
  endianness: typeof endianness;
  /** Return the operating system name. @since 0.0.0-alpha.0 */
  type: typeof type;
  /** Return the machine hardware type string. @since 0.0.0-alpha.0 */
  machine: typeof machine;
  /** Return estimated default parallelism count. @since 0.0.0-alpha.2 */
  availableParallelism: typeof availableParallelism;
  /** Return the operating system release string. @since 0.0.0-alpha.2 */
  release: typeof release;
  /** Platform-specific path to the null device. @since 0.0.0-alpha.2 */
  readonly devNull: typeof devNull;
  /** Operating system constants. @since 0.0.0-alpha.2 */
  readonly constants: OsConstants;
};
export default _default;

Default export object providing all node:os functions and EOL.