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

304
Views
Destructuring 'req.body.data' into 'req.body'

I am sending some data from the front end to the back end. I am trying to send data as an object to the back. When it arrives, it is obviously req.body.data, but should land in the backend as req.body. How do I destructure the request, either from the front or the back so that the back only receives req.body

front end

const { user } = await axios.post('http://localhost:3000/auth/signup', {data});

Backend (what I want)

if(req.body.type === 'vendor') {

Right now the backend received (What i dont want)

if(req.body.data.type....)
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Your passing data as an object prop. Just pass it directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', data)
about 4 years ago · Juan Pablo Isaza Report

0

You are sending object with data property when sending request to the backend. What you should do is destruct that data object and send its property directly:

const { user } = await axios.post('http://localhost:3000/auth/signup', { ...data });
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!