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

225
Views
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 answers
Answer question

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 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!