Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

231
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda