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

274
Vistas
Express server throws weird "cannot read properties of undefined reading "name" error.."

I'm trying to create a register route but the post request return cannot read properties of undefined. reading 'name'. And the "existUser" always returns true even though theres no user with the email in the database. Is there something that i'm missing here ? heres my route -

router.post('/register', async (req, res) => {
    try {
        const user = new User({
            name: req.body.name,
            email: req.body.email,
            password: crypto.AES.encrypt(req.body.password, process.env.CRYPTO_SEC).toString(),
            dateOfBirth: req.body.dateOfBirth,
        });
        const existUser = await User.findOne({ email: user.email });
        if (existUser) {
            return res.status(400).json({ msg: "Email Already Exist!" });
        } else {
            try {
                const newUser = await user.save();
                res.status(200).json(newUser);
            } catch (err) {
                res.status(400).json({ msg: err.message });
            }
        }
    } catch (err) {
        res.status(400).json({ msg: "An Error Occured!" })
    }
});

User model -

const mongoose = require('mongoose');

const userSchema = new mongoose.Schema({
    name: {
        type: String,
        required: true
    },
    email: {
        type: String,
        required: true
    },
    password: {
        type: String,
        required: true
    },
    dateOfBirth: {
        type: Date,
        required: true
    },
    profilePicture: {
        type: String,
        required: false,
        default: ""
    },
});

module.exports = mongoose.model("Users", userSchema);

How do I solve this weird error.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

probably the request body property is not being found.
confirm you are passing some middleware from bodyparser to express.

something like that:

const express = require('express');
const app = express();

app.use(express.json());
over 4 years ago · Santiago Trujillo Denunciar
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