<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rais</title>
    <description>The latest articles on DEV Community by Rais (@raisrais).</description>
    <link>https://dev.to/raisrais</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2512059%2F5ec9e47a-4b63-4ee3-bfb1-22da3b60b646.jpg</url>
      <title>DEV Community: Rais</title>
      <link>https://dev.to/raisrais</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/raisrais"/>
    <language>en</language>
    <item>
      <title>formdata posted in reactjs to nodjes backend arriving empty</title>
      <dc:creator>Rais</dc:creator>
      <pubDate>Mon, 02 Dec 2024 14:37:27 +0000</pubDate>
      <link>https://dev.to/raisrais/formdata-posted-in-reactjs-to-nodjes-backend-arriving-empty-3mk2</link>
      <guid>https://dev.to/raisrais/formdata-posted-in-reactjs-to-nodjes-backend-arriving-empty-3mk2</guid>
      <description>&lt;p&gt;so I have a nodejs backend which am trying to make a post request to using axios and am collecting the data at the frontend with formdata , all checks indicates that the formdata is populated however when it gets to the backend the formdata is empty, I tried working on my headers however nothing worked so far… I am could use some expert opinion&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//FrontEnd Code
const handleSubmit = async (e)=&amp;gt;{

  e.preventDefault();
 // console.log(bodyFormData)
 bodyFormData.append("email", email);
  bodyFormData.append("first_name", fName);
  bodyFormData.append("last_name", lName);
  bodyFormData.append("password", password);
  //Axios config
  const request = {
    method: "post",
    url: "http://localhost:9000/client/sign-up",
    body: bodyFormData,
    headers: {
      'Access-Control-Allow-Origin':'*',
      " content-Type":"application/json", 
      "X-Request-Platform": platform,
     },
  };  
  try {
    console.log(bodyFormData, request.body)
    console.log(platform)
    //const hashpassword = await bcrypt.hash(e, 10)
    const res= await axios( request)
     console.log(res.data)

//Form Data shown attached  from console log in browser's console, however //delivers an empty body at the backend
FormData(4) { email → "gunter@ilmenau.com", first_name → "dfdadf", last_name → "sdfsdsdf", password → "test1212" }

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;App.js backend &lt;br&gt;
const cors = require('cors');&lt;/p&gt;

&lt;p&gt;const bodyParser = require('body-parser')&lt;/p&gt;

&lt;p&gt;const multer = require('multer');&lt;/p&gt;

&lt;p&gt;const upload = multer();&lt;/p&gt;

&lt;p&gt;const forms = multer();&lt;/p&gt;

&lt;p&gt;mongodb_connection().then(() =&amp;gt; {&lt;/p&gt;

&lt;p&gt;console.log("App is connected to database");&lt;/p&gt;

&lt;p&gt;});&lt;/p&gt;

&lt;p&gt;(async () =&amp;gt; {&lt;/p&gt;

&lt;p&gt;await worker.start();&lt;/p&gt;

&lt;p&gt;})();&lt;/p&gt;

&lt;p&gt;const express = require("express");&lt;/p&gt;

&lt;p&gt;const app = express();&lt;/p&gt;

&lt;p&gt;app.use(cors());&lt;/p&gt;

&lt;p&gt;app.use(express.json());&lt;/p&gt;

&lt;p&gt;// for parsing application/json&lt;/p&gt;

&lt;p&gt;app.use(bodyParser.json());&lt;/p&gt;

&lt;p&gt;// for parsing application/xwww-&lt;/p&gt;

&lt;p&gt;app.use(bodyParser.urlencoded({ extended: true }));&lt;/p&gt;

&lt;p&gt;//form-urlencoded&lt;/p&gt;

&lt;p&gt;// for parsing multipart/form-data&lt;/p&gt;

&lt;p&gt;app.use(upload.array());&lt;/p&gt;

&lt;p&gt;app.use(forms.array());&lt;/p&gt;

&lt;p&gt;app.use(express.static('public'));&lt;/p&gt;

&lt;p&gt;// parse application/x-www-form-urlencoded&lt;/p&gt;

&lt;p&gt;However the formData always arrive empty&lt;/p&gt;

&lt;p&gt;App is connected to database&lt;br&gt;
Worker is connected to database&lt;br&gt;
{}&lt;br&gt;
Error creating user: Error: users validation failed: password: Cast to string failed for value "Promise {  }" (type Promise) at path "password", email: Path &lt;code&gt;email&lt;/code&gt; is required., first_name: Path &lt;code&gt;first_name&lt;/code&gt; is required., last_na&lt;/p&gt;

&lt;p&gt;PS: I have tweaked my headers and added and subtracted bodyparses a couple of times now am out of ideas &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
