Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

195
Vistas
UnhandledPromiseRejectionWarning: TypeError: No se puede leer la propiedad 'nombre' de indefinido, en mi api

Estoy probando mi API de NodeJs y se producen errores. Aquí está el código de la función que no funciona:

 const createUser = (req,res) => { const name = req.body.name; const email = req.body.email; const password = req.body.password; const newUser = new User({name:name, email:email, password:password}); //---- newUser.save() .then(() => res.json('200')) .catch(err => { if(err.keyPattern.name){ res.json("User already exists"); }else if(err.keyPattern.email){ res.json("Email already exists") }else{ res.status(400).json("ERROR:"+err); } }) }

No es la carpeta, porque todas las demás rutas funcionan. Intenté consolar el registro de todo hasta que la línea en la que escribí //----- , y todo se ve muy bien. Ahora, The Save Startement parece tener un problema. Aquí está el error completo:

 (node:12584) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'name' of undefined at C:\Users\mposs\OneDrive\Desktop\Files\projects\moondevdotenv\moondev.env\backend1\controller\userController.js:13:31 at processTicksAndRejections (internal/process/task_queues.js:93:5) (Use `node --trace-warnings ...` to show where the warning was created) (node:12584) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:12584) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

¿Alguien me puede ayudar? Gracias

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda