How to get the uptime of the system using Node.js?

Published March 26, 2021

To get the uptime of the system, you can use the uptime() method from the os module in Node.js.

/* Get uptime of system Node.js */

// import os module
const os = require("os");

// get the uptime of system
const uptime = os.uptime(); // 22345
  • The method returns the uptime of the system or time awake in seconds.

See the above code live in repl.it.

Feel free to share if you found this useful 😃.


Share on: Facebook Twitter