os and process
node:os exposes host capabilities; process exposes the current Node runtime - together they drive cluster sizing, health payloads, and environment configuration.
Search across all documentation pages
node:os exposes host capabilities; process exposes the current Node runtime - together they drive cluster sizing, health payloads, and environment configuration.
import { availableParallelism, hostname, totalmem, freemem } from 'node:os';
console.log({
host: hostname(),
cpus: availableParallelism(),
memFree: freemem(),
memTotal: totalmem(),
node: process.version,
pid: process.pid,
});When to reach for this:
/health and /ready diagnostic payloadsimport { availableParallelism, hostname, loadavg, platform, arch } from 'node:os';
export function hostSnapshot() {
return {
hostname: hostname(),
platform: platform(),
arch: arch(),
nodeVersion: process.version,
pid: process.pid,
ppid: process.ppid,
uptimeSec: process.uptime(),
cpuParallelism: availableParallelism(),
loadavg1m: loadavg()[0],
memory: process.memoryUsage(),
env: process.env.NODE_ENV ?? 'development',
};
}
export function assertProductionEnv(): void {
if (process.env.NODE_ENV === 'production' && !process.env.DATABASE_URL) {
throw new Error('DATABASE_URL required in production');
}
}import { monitorEventLoopDelay } from 'node:perf_hooks';
const h = monitorEventLoopDelay({ resolution: 20 });
h.enable();
setInterval(() => {
console.log('eventLoopP99Ns', h.percentile(99), 'rss', process.memoryUsage().rss);
h.reset();
}, 30_000).unref();What this demonstrates:
availableParallelism respects cgroup CPU limits in containers better than legacy cpus().lengthprocess.memoryUsage().rss tracks resident set - correlate with K8s OOM eventsloadavg Unix-specific - useful on Linux VMs, less on Windows| API | Meaning |
|---|---|
process.uptime() | Seconds since Node start |
process.ppid | Parent PID (1 in Docker after init) |
freemem() | OS free RAM |
tmpdir() | Temp directory path |
import { env } from 'node:process';
const nodeEnv = env.NODE_ENV ?? 'development';availableParallelism().| Alternative | Use When | Don't Use When |
|---|---|---|
| K8s metrics-server | Fleet memory/cpu | Local dev only |
| OpenTelemetry host metrics | Unified observability | Quick one-off script |
/proc/self Linux read | Deep container debug | Portable app code |
| Cloud instance metadata | AZ/region detection | On-prem bare metal |
Parallelism respects cgroup limits in Kubernetes - preferred for pool sizing.
Resident Set Size - physical RAM used by process - watch for OOM trends.
exit skips async cleanup - prefer graceful shutdown then natural exit.
process.env.NODE_ENV - validate with Zod at startup.
User home paths - rare in server containers - prefer explicit config paths.
Set process title for ps visibility - optional ops convenience.
argv user args; execArgv node flags like --import tsx.
freemem is host view - cgroup limit needs cgroups fs or external agent for accurate headroom.
Returns win32 - path and signal semantics differ from Linux.
version, uptime, pid, optional elu - avoid full host dump publicly.
cluster Module uses availableParallelism.
Diagnostic report on crash - see Reading Official Docs.
Stack versions: This page was written for Node.js 24.18.0 (Active LTS), npm 10+, TypeScript 5.6+, Express 5, Fastify 5, and NestJS 11.
Reviewed by Chris St. John·Last updated Jul 16, 2026