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

425
Views
Comprobar si req.body está vacío no funciona con express

Traté de probar mi solicitud de inicio de sesión en cartero con un cuerpo vacío, pero esta verificación no funciona. Va más allá y ejecuta el resto del código. Por qué ? ¿Hay otra forma de verificar si el cuerpo está vacío?

 route.post("/login", (req, res) => { console.log(req.body); if (!req.body) { console.log("I am here"); res.status(400).send({ message: "Content cannot be empty" }); return; } ... // check password etc }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Puede verificar cuántas claves tiene req.body

 if (Object.keys(req.body).length === 0) { console.log("I am here"); res.status(400).send({ message: "Content cannot be empty" }); return; }
over 4 years ago · Santiago Trujillo Report

0

Puede verificar la longitud del Cuerpo: if (Objects.keys(req.body).length === 0) {

over 4 years ago · Santiago Trujillo Report

0

Puedes usar:

if(Object.keys(req.body).length === 0)

o Object.getOwnPropertyNames(req.body).length == 0

luego agrega tu lógica.

over 4 years ago · Santiago Trujillo 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!