OS Host Machine Facts Report
os.hostname, freemem, totalmem, uptime, loadavg, and availableParallelism read the running machine, with loadavg documented as zero on Windows.
Code
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\guangmingHow 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
Git Conventional Commit BuilderBuild and validate Conventional Commits v1.0.0 messages with type, scope, breaking markers, 72-char subject counter, body, footers, and git CLI command.Glob Pattern TesterCompile glob patterns with *, **, ?, character classes, and braces into regex and test them against a list of candidate file paths.Tar Archive Command BuilderBuild safe tar create, extract, and list commands for gzip, xz, zstd, and bzip2 archives with excludes, target directory (-C), and flag explanations.
FAQ
- Are there third-party dependencies?
- No. The imports resolve to Node.js core modules, which the runtime provides.
Report a problem with this exampleOpens a pre-filled issue on GitHub.