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

226
Vistas
error in sending data to mongodb from my own api

Actually, I was developing a flutter application that sends the data to my own API created in node js and then the data goes to MongoDB cluster, when I tested the API so it was working and the data goes to MongoDB but when I tried to send the data from my flutter app so it is giving the following error:

(node:4856) UnhandledPromiseRejectionWarning: ValidationError: User validation failed: name: Path `name` is required., email: Path `email` is required., password: Path `password` is required.

I think that the required data is not receiving to MongoDB so I created a simple javascript app that sends that data to the API, but I WAS receiving the same error, I think that this is the error from my API, but It is still ok when I send the data from the postman, or thunder-client. This is the code of API I have created:

const DB = "mydburl"

app.use(express.json());
    app.post('/api/signup', async (req, res) => {
    const {name, email, password} = req.body;

    const existingUser = await User.findOne({ email });
    if (existingUser) {
        return res.status(400).json({ msg: "User with same email already already exists" })
    }
    const hashedPassword = await bcryptjs.hash(password, 8);
    let user = new User({
        email,
        password : hashePassword,
        name,
    });
    res.json(user)
    user = await user.save();
    console.log(user);
}); 



mongoose.connect(DB).then(() => {
    console.log("connection succesful")
})
.catch((e) => {
    console.log(e);
})


app.listen(PORT, "0.0.0.0", () => {
    console.log(`connected at port ${PORT}`)
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

 app.post('/api/signup', async (req, res) => {
    const {name, email, password} = req.body;
    console.log(`name=${name} , email = ${email} , password=${password}`);

    const existingUser = await User.findOne({ email });
    if (existingUser) {
        return res.status(400).json({ msg: "User with same email already already exists" })
    }
    const hashedPassword = bcryptjs.hashSync(password, 8);
    let user = new User({
        email:email,
        password : hashePassword,
        name:name
    });
    user.save().then((userSaved)=>{
        return res.status(200).json(user);
    }).catch((e)=>{
        return res.status(500).json({status:"error",error:e})
    });
   
}); 
about 4 years ago · Juan Pablo Isaza 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