OS Host Machine Facts Report

os.hostname, freemem, totalmem, uptime, loadavg, and availableParallelism read the running machine, with loadavg documented as zero on Windows.

JavascriptCli Tooling

Code

javascriptsnippet
15 lines
import os from 'node:os';

const gib = (bytes) => (bytes / 2 ** 30).toFixed(2);

// Hostname, memory and uptime come straight from the running machine
console.log('hostname:', os.hostname());
console.log('freemem GB:', gib(os.freemem()), 'of', gib(os.totalmem()));
console.log('uptime days:', (os.uptime() / 86_400).toFixed(2));
// loadavg is a no-op on Windows: it reports [0, 0, 0]
console.log('loadavg:', os.loadavg().map((n) => n.toFixed(2)).join(' '));
console.log('cpus:', os.cpus().length, '| parallelism:', os.availableParallelism());
console.log('user:', os.userInfo().username);
console.log('platform:', os.platform(), '| release:', os.release());
console.log('devNull:', os.devNull);
console.log('homedir:', os.homedir());

Output

Captured from a sandboxed run of this snippet in the build pipeline.

hostname: DESKTOP-UHJAGQ6
freemem GB: 1.97 of 15.88
uptime days: 1.01
loadavg: 0.00 0.00 0.00
cpus: 6 | parallelism: 6
user: guangming
platform: win32 | release: 10.0.26320
devNull: \\.\nul
homedir: C:\Users\guangming

How it works

Structurally, expect the function gib and nothing else.

Caveats

  • The only import, node:os, is part of the Node.js standard library.

Applying it

The entry-point signature is const gib = (bytes)

The run emits 9 labeled sections — hostname:, freemem GB:, uptime days:, loadavg:, cpus:, user:, platform:, devNull:, homedir: — one per step.

Statements that matter

const gib = (bytes) => (bytes / 2 ** 30).toFixed(2);

Interactive Tools for This Topic

FAQ

Are there third-party dependencies?
No. The imports resolve to Node.js core modules, which the runtime provides.