get system boot time in typescript

To get the system boot time in TypeScript, you can use the os module that comes with Node.js.

Here is the code:

index.ts
import os from 'os';

const uptimeInSeconds = os.uptime();
const bootTime = new Date(Date.now() - (uptimeInSeconds * 1000));
console.log(`System Boot Time: ${bootTime}`);
171 chars
6 lines

In the code above, first we import the os module. Then we use the os.uptime() method to get the uptime of the system in seconds. We then subtract the uptime from the current time (Date.now()) to get the boot time of the system. We log the boot time to the console.

gistlibby LogSnag