On my express server, I have this POST function that takes parsed data lines from raspberry Pis and writes them on a postgresql database, every minute or so.
I have a lot of algorithms that run on the rPi and make calculations with these data lines but I would like to migrate all the calculation to the server side and have the algorithms located on the same machine as my Express code.
So the same POST function that inserts data into the sql database would push the raw data to my program as js variables that I can call in functions. However, I do not know the proper syntax to do this? Or would there be a simpler way to do this?
Thanks!
Here is my code:
router.post("/", async (req, res) => {
try {
const {name, position1, position2, batt_lvl} = req.body
const newPosition = await pool.query(
"INSERT INTO position (name, position1, position2 batt_lvl) VALUES ($1, $2, $3, $4) RETURNING *",
[name, position1, position2, batt_lvl])
res.json(newPosition.rows[0]);
} catch (err) {
console.error(err.message)
}
})
router.get("/", async (req, res) => {
try {
const allPositions = await pool.query("SELECT * FROM positions");
res.json(allPositions.rows)
} catch (err) {
console.error(err.message)
}
})