0

Basically, I have a form that posts to my Node.js form. When I try to console.log the body I get {}. I can't understand why even because I have another form that submits on another endpoint in the same server and contains content in the body. I already have app.use(express.urlencoded({extended: true})); in my code In the HTML file, I have:

<form id="form" action="/api/new/post" method="post" enctype="multipart/form-data">
(all the inputs like: <input name="title" id="title" type="text"> )
</form>

In the app.js I have:

const api = express.Router()
app.use(express.urlencoded({extended: true}));
app.use('/api/', api)
api.post('/new/recipe', (req, res)=>{
    const {title, description, advices, people} = req.body
    console.log(req.body)
    res.send('OK')
})
espo
  • 3
  • 4
  • 1
    Please read [ask]; in particular the part about providing a [mcve] – Quentin Feb 27 '23 at 20:56
  • 1
    `enctype="multipart/form-data"` does not match `express.urlencoded` – Quentin Feb 27 '23 at 21:24
  • 1
    Does this answer your question? [multipart/form-data returns empty object | Nodejs](https://stackoverflow.com/questions/67082969/multipart-form-data-returns-empty-object-nodejs) and also: [Req.body is empty in express even i did everything](https://stackoverflow.com/questions/67972495/req-body-is-empty-in-express-even-i-did-everything) – traynor Feb 28 '23 at 07:06

0 Answers0