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)
| Operation | Source |
|---|---|
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
| Operation | Source |
|---|---|
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:
username—System.getProperty("user.name").homedir—System.getProperty("user.home").uid/gid— POSIX: FFM down-calls to the system linker'sgetuid/getgid. Windows (or when native access is denied):-1.shell— POSIX:SHELLenvironment variable, may benullif unset. Windows:null.options.encoding—'buffer'returnsusername,homedir, andshellas UTF-8-encodedUint8Arrayinstances; 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 bytesDeferred 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: