I am having trouble interpreting the following POST request sent via Postman in Express.js: (sending "temp": 97.7, "device": "one"
)
My POST router (in ./routes/sensors) is a simple
router.post('/', function(req, res, next) {
console.log(req.body)
});
and my index.js contains
var sensorsRouter = require('./routes/sensors');
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use('/sensors', sensorsRouter);
Question: When I send the above mentioned POST request, my console understands it's a POST, but the output of req.body
is empty: {}
How can I interpret the "temp" and "device" sent as a POST request in Express.js? I found many instructions involving body-parser, but as far as I understand express.json and express.urlencoded are supposed to be used instead these days.