get system cpu count in typescript

To get the system's CPU count in a TypeScript Node.js application, you can use the Node.js os module as follows:

index.ts
import os from 'os';

const cpuCount = os.cpus().length;
console.log(`CPU count: ${cpuCount}`);
96 chars
5 lines

Here, we import the os module and use its cpus() function to get an array of objects containing information about each CPU/core on the system. We then get the length of this array to determine the total number of CPUs/cores on the system.

Finally, we log the CPU count to the console.

related categories

gistlibby LogSnag