To get the system CPU temperature in Celsius using TypeScript in Node.js, you can use the systeminformation
package which provides a simple interface to access hardware information. Here's an example:
index.ts284 chars14 lines
First, we import the systeminformation
package. Then we define an async
function called getCpuTemperature
which uses the cpuTemperature()
method of systeminformation
to get the temperature data. We extract the main temperature value from the data and return it.
In the main code block, we call getCpuTemperature()
and log the result to the console. Note that cpuTemperature()
returns the temperature in Celsius by default. If you want to get the temperature in Fahrenheit, you can pass false
as the second argument to the method.
gistlibby LogSnag