'Get posting some data instead of POST MERN
Hi I'm new to the MERN stack development but when I encountered weird scenario when I'm using postman to check if my data is pushing to the backend. Here are my codes below,
router.route('/addUser').post((req, res) => {
const name = req.body.name;
const email = req.body.email;
const phone = req.body.phone;
const loc = req.body.loc;
const date = req.body.date;
const newUserAddition = new User ({name, email, phone, loc, date});
newUserAddition.save()
.then(user => res.json('New Record Added!'))
.catch (err => res.status(400).json('Error:' + err));
});
When I click the post button this will be the error
Cannot POST /user/addUser
but when I change it to GET. It insert the data successfully
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
