I am building a MERN app where I want to use a POST method to send data to my collection in MONGODB.
I imported schema as Messages
here is the code
app.post("/messages/new",(req,res) => {
const dbMessage = req.body;
Messages.create(dbMessage,(err,data) => [
if(err){
res.status(500).send(err);
}
else{
res.status(201).send(data);
}
});
});
The above way is depreciated which I found later.
What is the latest way to handle this?
2
Answers
I found an answer
You made typo on line 2:
Another typo on line 3: