1
I have basically two files. HTML, so:
<form action="/result", method="POST">
<input id="phrase" type="text" name="phrase" value="Processar frase" />
<input type="submit" value="Processar!" />
</form>
And an Express app:
const express = require('express');
var app = express();
app.use(express.json());
app.post('/result', (req, res) => {
res.json(req.body);
});
Basically, when I send any data by the form, the endpoint /result
returns an empty object to req.body
:
{}
Instead of returning the value passed in the form field, as I expected. I have tried several ways and seen many people talking about using the body-parser, however, I also saw that he is depreciated, for this reason I prefer not to use.
Why am I not receiving the data as expected?