testing the latest

main
Gerardo Marx 6 days ago
parent d35fe5cd6d
commit fee130a06c

@ -69,6 +69,21 @@ app.get('/api/measurements', (req, res) => {
res.json(measurements); res.json(measurements);
}); });
app.get('/api/measurements/latest', (req, res) => {
// Check whether any measurements exist.
if (measurements.length === 0) {
return res.status(404).json({
error: 'No measurements yet'
});
}
// The last array element is the latest submitted measurement.
const latest = measurements[measurements.length - 1];
res.json(latest);
});
// starting the listening service // starting the listening service
app.listen(3030, () => { app.listen(3030, () => {
console.log('Server running at http://localhost:3030'); console.log('Server running at http://localhost:3030');

Loading…
Cancel
Save