Node.js Reference ยท process
Node.js process.uptime() method
Reference for process.uptime() in Node.js: seconds the process has been running, with fractions, compared with os.uptime(), Date.now() and performance.now().
process.uptime() returns how many seconds the current Node.js process has been running, as a floating-point number with fractional seconds. It is measured with a monotonic clock, so changes to the system time do not affect it.
It is a convenient value for health checks, startup-time logs and "up for 3 hours" displays. It counts from the moment the process started, not from when your script began running, so it includes Node's own boot time.
console.log(process.uptime()); // e.g. 0.048
Try it
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.
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
process.uptime(): number
Returns: the number of seconds (a double) since the process started. Fractional digits give sub-second precision.
Usage notes
- Not wall-clock time. Use
Date.now()for timestamps; useuptime()for durations since start. A system clock change does not moveuptime(). - Includes startup. Node's own bootstrap (and
--requiremodules) is counted, so even the first line of your script sees a small positive value. - Different from
os.uptime(), which reports how long the whole machine has been running. - Timing short code is better done with
performance.now()orprocess.hrtime.bigint(), which are designed for it. - Health endpoints often return
process.uptime()so monitoring can notice unexpected restarts (a value that drops back to near zero). - Precision is not guaranteed to the last digit; do not compare two values for exact equality.
- Workers. Inside a
worker_threadsworker, the value is the uptime of the whole process, not of the worker. - Rounding. Use
Math.floor()for display;toFixed()returns a string.