os
Node's own lib/os.js, in TypeScript, over the host reads libuv makes: os.cpus() returns live per-core tick counters, os.networkInterfaces() walks the real adapters, os.release()/version() answer what Node answers on the same machine, and a failed call throws Node's ERR_SYSTEM_ERROR. os.cpus() speed reports the fixed 2400 MHz libuv nominal on Apple Silicon (where hw.cpufrequency is unavailable), cpufreq's scaling_max_freq or 0 on Linux (VMs and containers have no cpufreq), and Darwin times.irq is 0 — all exactly what real Node reports on that hardware. As in Node, the functions convert to their result: `${os.hostname}` is the host name.
os.platform()
ExactReturns the operating-system platform string — process.platform, as Node's platform() returns.
Returnsstring — The platform identifier (e.g. "darwin", "linux").
console.log(os.platform().length > 0); // trueos.homedir()
ExactReturns the current user's home directory, mirroring libuv's uv_os_homedir: a set HOME wins (an empty one included, matching Node's ""); on POSIX an unset HOME falls back to the passwd database, and only a failed lookup throws ERR_SYSTEM_ERROR. Windows reads USERPROFILE, else the process token's profile directory.
Returnsstring — The home directory path.
const home = os.homedir();
console.log(home.length > 0); // trueos.tmpdir()
ExactReturns the default temporary-file directory: on POSIX the first set, non-empty one of TMPDIR, TMP and TEMP (Node's getTempDir) with one trailing slash stripped, else "/tmp"; on Windows TEMP, TMP, then <SystemRoot|windir>\temp. Never throws.
Returnsstring — The temp directory path.
const tmp = os.tmpdir();
console.log(tmp.length > 0); // trueos.hostname()
ExactReturns the host name of the operating system (gethostname); a failure throws ERR_SYSTEM_ERROR.
Returnsstring — The host name.
const host = os.hostname();
console.log(host.length > 0); // trueos.cpus()
ExactReturns real per-core {model, speed, times: {user, nice, sys, idle, irq}} objects — Linux via /proc/cpuinfo and /proc/stat parsing, Darwin via sysctlbyname and Mach host_processor_info — both verified (on Apple Silicon M4 Pro, model = "Apple M4 Pro" with live tick counters). On Apple Silicon, where hw.cpufrequency is unavailable, speed reports the fixed 2400 MHz nominal that real Node/libuv reports there; on Linux it reflects /proc/cpuinfo's current/scaled cpu MHz, matching real Node. Darwin times.irq is 0, exactly as real Node reports on Darwin.
Returnsobject[] — One entry per logical core.
const cpus = os.cpus();
console.log(cpus.length > 0); // true
console.log(cpus[0].model.length > 0); // trueos.totalmem() / os.freemem()
ExactReturn the total and free system memory in bytes. Verified on Linux and on Apple Silicon M4 Pro — totalmem() matches sysctl hw.memsize, and Darwin freemem() (Mach host_statistics) returns a live free-page figure.
Returnsnumber — Bytes of total or free memory.
const total = os.totalmem();
const free = os.freemem();
console.log(free > 0 && free <= total); // trueos.EOL
ExactThe operating-system-specific end-of-line marker: "\r\n" on Windows, "\n" on POSIX.
Returnsstring — "\r\n" on Windows, "\n" elsewhere.
os.type() / os.release() / os.version() / os.machine()
ExactThe uname-shaped identity strings. POSIX reads uname(); Windows reports "Windows_NT", RtlGetVersion's major.minor.build, the registry ProductName with libuv's "Windows 10" → "Windows 11" rewrite for build ≥ 22000, and x86_64/arm64 — verified byte-identical to Node on Windows 11.
Returnsstring — e.g. "Linux" / "6.8.0-45-generic" / "#45-Ubuntu SMP …" / "x86_64".
console.log(os.type(), os.release(), os.machine());os.arch() / os.endianness() / os.devNull
Exactprocess.arch; the host's byte order ("LE" or "BE"); and the null device ("\\\\.\\nul" on Windows, "/dev/null" elsewhere).
console.log(os.arch(), os.endianness(), os.devNull);os.uptime() / os.loadavg() / os.availableParallelism()
Exactlibuv's sources: seconds since boot as a double (CLOCK_BOOTTIME on Linux, kern.boottime on Darwin, GetTickCount64 on Windows); the 1/5/15-minute load averages via getloadavg, [0, 0, 0] on Windows as in Node; the CPUs this process may run on (the affinity set on Linux, the online count elsewhere, GetActiveProcessorCount on Windows), at least 1.
console.log(os.uptime() > 0, os.loadavg().length, os.availableParallelism() >= 1);os.userInfo()
ExactThe effective user's passwd entry on POSIX (uv_os_get_passwd); on Windows uid and gid are -1, username comes from GetUserNameW, homedir is os.homedir() and shell is null — exactly what Node reports. { encoding: 'buffer' } gives Buffers; a failed lookup throws ERR_SYSTEM_ERROR.
Returnsobject — { uid, gid, username, homedir, shell }.
const u = os.userInfo();
console.log(u.username, u.homedir === os.homedir());os.networkInterfaces()
ExactAn object keyed by interface name, each an array of { address, netmask, family, mac, internal, cidr, scopeid } records in libuv's order, with scopeid on IPv6 entries only. getifaddrs (up + running interfaces, MAC from the link-layer entry) on POSIX, GetAdaptersAddresses on Windows; cidr is Node's own getCIDR over the netmask.
const nis = os.networkInterfaces();
for (const name of Object.keys(nis)) {
for (const ni of nis[name]) console.log(name, ni.family, ni.address, ni.cidr);
}os.getPriority() / os.setPriority()
Works, with caveatsA process's scheduling priority (-20 highest to 19 lowest; pid 0 is this process) through getpriority/setpriority — on Windows the priority class, mapped as libuv maps it. Node's argument validation; a failure throws ERR_SYSTEM_ERROR with the failed call's info ({ errno, code, message, syscall }).
os.setPriority(10);
console.log(os.getPriority()); // 10
try { os.getPriority(999999) } catch (e: any) { console.log(e.info.code) } // ESRCH- The error's
errno/syscallare copies ofinfo's, not accessors over it.
os.constants
ExactThe host's dlopen flags, errno codes, signal numbers and priority levels as null-prototype objects, signals frozen, in Node's own order (node_constants.cc); on Windows errno also carries the WSA* codes.
Returnsobject — { UV_UDP_REUSEADDR, dlopen, errno, signals, priority }.
console.log(os.constants.signals.SIGTERM, os.constants.errno.ENOENT, os.constants.priority.PRIORITY_HIGHEST);