Hi all,
this should be a 'hello world' type of question for all the experienced people out there, but I am struggling to get it working. I'm trying to get CPU temperature readings from a Raspberry Pi using the systeminformation package and then display the output through an express api, in my local network.
This simple code does work and outputs the temperature reading to the console:
But I can't seem to grasp how to output this in a super-simple API. Currently my code is this:
It does start a server on port 3389, but going to http://ipaddressofmypi:3389/ only gives me "{}" in the browser, then the temperature reading is displayed again in the console... I know I'm close, but I just can't seem to jump through the last hurdle.
Help?
this should be a 'hello world' type of question for all the experienced people out there, but I am struggling to get it working. I'm trying to get CPU temperature readings from a Raspberry Pi using the systeminformation package and then display the output through an express api, in my local network.
This simple code does work and outputs the temperature reading to the console:
JavaScript:
const si = require('systeminformation');
si.cpuTemperature()
.then(data => console.log(data))
.catch(error => console.error(error));
But I can't seem to grasp how to output this in a super-simple API. Currently my code is this:
JavaScript:
const si = require('systeminformation');
const express = require('express');
const app = express();
const port = 3389;
app.listen(port, () => {
console.log(`Server running on port ${port}`);
});
app.get("/", (req, res, next) => {
res.send(
si.cpuTemperature()
.then(data => console.log(data))
.catch(error => console.error(error)));
});
It does start a server on port 3389, but going to http://ipaddressofmypi:3389/ only gives me "{}" in the browser, then the temperature reading is displayed again in the console... I know I'm close, but I just can't seem to jump through the last hurdle.
Help?