Unable to send data from react to express server

I am trying to send data from react to express server.

React code:

const imageRenderer = async () => {
  const res = await axios({
    method: "post",
    url: "http://localhost:8080/previewRender",
    data: selectedFile.filePaths,
  });
console.log(res.data);

};

Express code:

app.post("/previewRender", (req, res) => {
  var fileLocation = req.body;
  console.log(fileLocation); 
});

However in console the filelocation is shown as undefined. selectedFile.filePaths is of type object. Can’t I send object to express?

Answer

Did you use app.use(express.json()) in your app.js?