Skip to content
Tutorials Center
My learning

Topics

Node.js Reference ยท path, os and url

Node.js os.uptime() and os.loadavg() methods

Reference for os.uptime() and os.loadavg() in Node.js: seconds since boot, 1, 5 and 15 minute load averages, and why Windows always reports zeros.

os.uptime() returns the number of seconds the system has been running, as a number that can have a fractional part. os.loadavg() returns an array of three numbers: the average system load over the last 1, 5 and 15 minutes.

Load average counts how many processes are running or waiting to run, so a value near the number of CPUs means the machine is fully busy. Do not confuse the machine's uptime with process.uptime(), which measures only how long your Node.js process has been alive.

NODE
import os from "node:os";

const [one, five, fifteen] = os.loadavg();
console.log(one, five, fifteen);

Try it

Node.js Reading both values

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Node.js Formatting uptime

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Syntax

NODE
os.uptime(): number
os.loadavg(): [number, number, number]
Name Description
(none) Neither function takes arguments.

Returns: uptime() is seconds since boot. loadavg() is [1 minute, 5 minutes, 15 minutes].

Edge cases: on Windows loadavg() always returns [0, 0, 0], because the platform has no such metric. Sandboxed or containerized systems may report the host's values.

Usage notes

  • Normalize by CPU count. A load of 4.0 is calm on a 16-core server and a crisis on a single-core one. Divide by os.availableParallelism().
  • Trends matter more than a single number. If the 1-minute value is higher than the 15-minute value, load is rising.
  • Load is not CPU use. Processes blocked on disk I/O count too, so a high load can come from slow storage while CPUs sit idle.
  • Windows needs another source. Sample os.cpus() times twice or use a system tool.
  • Uptime can include sleep time on some platforms and exclude it on others.
  • Use it for health endpoints carefully: expose derived values, not raw system data, on public routes.