get system cpu temperature in typescript

To get the system CPU temperature in TypeScript, you can make use of the node-cpu-temperature library. First, install the library using npm:

index.ts
npm install node-cpu-temperature
33 chars
2 lines

Then, import the library and use it to get the CPU temperature:

index.ts
import * as cpuTemperature from 'node-cpu-temperature';

cpuTemperature.getTemperature().then((temperature: number) => {
  console.log(`CPU Temperature: ${temperature}°C`);
}).catch((error: Error) => {
  console.error(error.message);
});
238 chars
8 lines

The getTemperature() function returns a promise that resolves with the CPU temperature in Celsius. You can then use this value as needed in your TypeScript code.

gistlibby LogSnag