Not able to get data (node.js) from my client (react.js)

I’m not able to retrieve the data I’m sending from the client to the server.

My react code is the following:'http://localhost:5000/post-entry', { data: formData })
.then(res => {

My server code is the following:'/post-entry', (req, res) => {
  console.log(, " here");

When it reaches the post on my server, the log is undefined.

What am I doing wrong?

>Solution :

If formData is a JS object, just'http://localhost:5000/post-entry', formData) is enough.
You can access this object on server side by req.body. But ExpressJS needs a middleware to parse request bodies. You have to use app.use(express.json()) or app.use(bodyParser.json()) where bodyParser is body-parser.

Leave a Reply