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

319
Views
El nodo JS MSQL no puede leer la propiedad 'longitud' de undefined

quiero verificar si el usuario existe en la base de datos, pero recibí este error cuando agrego resultados.longitud:

(nodo: 12124) UnhandledPromiseRejectionWarning: TypeError: No se puede leer la propiedad 'longitud' de undefined

Este es el código:

 const mysql = require('mysql') const jwt = require('jsonwebtoken'); const bcrypt = require('bcryptjs'); exports.register = (req, res) => { console.log(req.body); const { name, email, password, passwordConfirm } = req.body; db.query('SELECT email FROM users WHERE email = ?', [email], async (error, results) => { if (error) { console.log(error); } if (results.length > 0) { return res.render('register', { message: 'That email is already in use' }) } else if (password !== passwordConfirm) { return res.render('register', { message: 'Passwords do not match' }); } let hashedPassword = await bcrypt.hash(password, 8); console.log(hashedPassword); }); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Eso parece bastante sencillo... Si el usuario no existe, results no están definidos, por lo que su condición no debería verificar los results.length .

 if (results !== undefined) { return res.render('register', { message: 'That email is already in use' }) }
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!