node:os

Node.js os module, resolvable via both ESM import and CommonJS require. JVM-backed — every value is resolved through standard Java APIs (system properties, ManagementFactory, InetAddress) or, where the JVM has no equivalent, via FFM down-calls to POSIX symbols.

Implemented operations

Resolved at class-init (cached constants)

OperationSource
arch()System.getProperty("os.arch") normalised to Node's token set (x64, arm64, …)
platform()Normalised os.name (linux, darwin, win32)
type()Linux / Darwin / Windows_NT
endianness()ByteOrder.nativeOrder()"LE" / "BE"
machine()Raw os.arch (e.g. "x86_64", "arm64")
release()os.version
version()os.version
tmpdir()ELIDE_SYS_TMP environment variable if set, otherwise java.io.tmpdir
homedir()user.home
availableParallelism()Runtime.availableProcessors()
EOL"\r\n" on Windows, "\n" elsewhere
devNull"\\\\.\\nul" on Windows, "/dev/null" elsewhere

Dynamic

OperationSource
hostname()InetAddress.getLocalHost().getHostName()
userInfo([options])user.name + user.home + FFM getuid()/getgid() + SHELL env
networkInterfaces()java.net.NetworkInterface enumeration

os.userInfo([options])

Returns { username, uid, gid, shell, homedir }. Behaviour:

  • usernameSystem.getProperty("user.name").
  • homedirSystem.getProperty("user.home").
  • uid / gid — POSIX: FFM down-calls to the system linker's getuid / getgid. Windows (or when native access is denied): -1.
  • shell — POSIX: SHELL environment variable, may be null if unset. Windows: null.
  • options.encoding'buffer' returns username, homedir, and shell as UTF-8-encoded Uint8Array instances; any other value (including the default) returns them as JS strings.
javascript
const os = require("node:os");

const info = os.userInfo();
info.username; // → "alice"
info.homedir; // → "/home/alice"
info.uid; // → 1000 (POSIX), -1 (Windows)
info.shell; // → "/bin/bash" (POSIX), null (Windows)

const buf = os.userInfo({ encoding: "buffer" });
buf.username; // → Uint8Array of UTF-8 bytes

os.networkInterfaces()

Returns an object keyed by interface name; each value is an array of assigned address records enumerated via java.net.NetworkInterface:

  • address — the numeric address (IPv6 is RFC 5952-compressed, e.g. ::1).
  • netmask — the subnet mask.
  • family — the string "IPv4" or "IPv6".
  • mac — the hardware address as xx:xx:xx:xx:xx:xx (00:00:00:00:00:00 when the interface exposes none).
  • internaltrue for a loopback interface.
  • cidraddress/prefixlen.
  • scopeid — the scope id (IPv6 records only).
javascript
const os = require("node:os");

const nets = os.networkInterfaces();
// → { lo: [ { address: "127.0.0.1", netmask: "255.0.0.0", family: "IPv4",
//            mac: "00:00:00:00:00:00", internal: true, cidr: "127.0.0.1/8" },
//          { address: "::1", family: "IPv6", internal: true, scopeid: 0, ... } ],
//     eth0: [ … ] }

Deferred to follow-up

These are wired into the namespace shape but throw UnsupportedOperationException on call — will be replaced by Rust-FFI paths in a later commit: cpus(), freemem(), totalmem(), uptime(), loadavg(), getPriority(), setPriority(), constants.

See also

  • Node.js upstream: