From 0ab91f7b594b2b0336a29ac5afd9cc7fa7e6e67f Mon Sep 17 00:00:00 2001 From: Gerardo Marx Date: Wed, 28 Oct 2026 23:42:16 -0600 Subject: [PATCH] receiving measurements --- index.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index ccbd719..cdc24e8 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,6 @@ const express = require('express'); - const app = express(); +app.use(express.json()); const sensors = [ { @@ -16,6 +16,8 @@ const sensors = [ ]; +const measurements = []; //empty + app.get('/', (req, res) => { res.send('Sensor Logger'); @@ -42,8 +44,27 @@ app.get('/api/sensors/:id', (req, res) => { res.json(sensor); }); +app.post('/api/measurements', (req, res) => { + // crequire json submission + + // 1. Receive the measurement. + const measurement = req.body; + + // verify object + + // Validate submitted fields and sensor id + + // 2. Store it in memory. + measurements.push(measurement); + // 3. Show it in the server terminal. + console.log('Received:', measurement); + + // 4. Confirm that it was stored. + res.status(201).json(measurement); +}); +// starting the listening service app.listen(3030, () => { console.log('Server running at http://localhost:3030'); });