get system boot time in seconds in javascript

You can use the systeminformation package in Node.js to get the system boot time in seconds. Here's an example:

index.tsx
const si = require('systeminformation');

si.system()
  .then(data => {
    const bootTimeInSeconds = Math.floor((new Date().getTime() - data.bootTime) / 1000);
    console.log(`System boot time: ${bootTimeInSeconds}s`);
  })
  .catch(error => console.error(error));
267 chars
9 lines

The system() method returns a promise that resolves to an object containing various system information, including the bootTime property, which is the timestamp of the system boot time. We calculate the difference between the current time and the boot time and convert it to seconds. The result is then logged to the console.

gistlibby LogSnag