Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

297
Views
How to get access my data (username, password etc;) from FormData() into my express server

I'm currently trying to get the correct part of my data (the actual Username Value and Password Value by itself so I can extract it and save it to a value etc;) from FormData which I sent through a POST request to my express server but I can't seem to get it, it either comes back undefined when I try doing req.body.username OR req.body.name or prints all of my FormData when I do req.body:

'------WebKitFormBoundarymqLPaiCoVje2rgBB\r\nContent-Disposition: form-data; name': '"username"\r\n' +
'\r\n' +
'myNamePutInHere\r\n' +
'------WebKitFormBoundarymqLPaiCoVje2rgBB\r\n' +
'Content-Disposition: form-data; name="password"\r\n' +
'\r\n' +
'password123\r\n'

My Express Server: (NOTE: I also tried req.body.username but that didn't work either)

const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true }))

app.post('/', function(req, res) {
  res.send(req.body.name)
  console.log(req.body.name)
});

My JS to send it:

  const form = document.getElementById( "signUpForm" );
  const XHR = new XMLHttpRequest();
  const FD = new FormData( form );

  XHR.open( "POST", "http://localhost:3001/", true);
  XHR.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  XHR.send(FD);

My HTML form:

<form id="signUpForm" name="signUpForm">
          <div class="flex flex-col">
              <input type="text" name="username" placeholder="Username*" class="w-10/12 mr-2 h-7 border-2 mb-3 rounded-lg py-4 px-3 signupinput" required>
              <input type="password" name="password" placeholder="Password*" class="w-3/6 h-7 border-2 mr-2 rounded-lg py-4 px-3 signupinput" required>
          </div>
          <button class="w-40 h-10 text-white bg-main-blue hover:bg-blue-300 rounded-lg mt-12" type="submit" value="Submit">Create an account</button>
</form>

Any help would be great, Thankyou in advance

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

try arrow functions. log from your request at frontend first then log from whole req object on backend. then you can find body

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!