M
M
Maxim2021-06-08 12:22:57
Express.js
Maxim, 2021-06-08 12:22:57

How to get data from Express.js post request?

Good afternoon, I am making a request from the front

const url = 'http://127.0.0.1:8080';
        let val = e.target.querySelector('input').value.trim() // Тут данные есть проверял через консоль
        let data = new FormData()
        data.append('tel', val)
        fetch(url, {
          method: 'POST',
          body: data
        }).then(response => {
          console.log(response)
        }).catch(error => {
          throw new Error(error)
        })


On the Express.js server, I accept the request like this:
app.post('/', (req, res) => {
  console.log(req.params);
  res.sendStatus(200);
});


req.params is always empty, and so is req.body.

How do I get data from the front?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
WapSter, 2021-06-08
@wapster92

https://www.npmjs.com/package/body-parser

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question