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

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

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(), networkInterfaces(), getPriority(), setPriority(), constants.

See also

  • Node.js upstream: