Re: How to handle a post request in JavaScript from Arduino
Posted: Fri Apr 29, 2022 3:19 am
you'll have to specify the content-type for body-parser to work
this example will work if you add an header with "Content-type: text/plain;" to the POST in your arduino code
this example will work if you add an header with "Content-type: text/plain;" to the POST in your arduino code
Code: Select all
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.text()) // body-parse will look for 'text' content
app.get('/', (req, res) => {
res.send('hello world')
})
app.post('/', (req, res) => {
console.log("post triggered")
console.log(req.body)
res.send('got it')
})
app.listen(3000, function () {
console.log('Example app listening on port 3000!');
})