I am having a strange problem while writing my api. I am using Nodejs and express. The problem occurs when i try to use GET with parameters.
This is my routes code
router.get('/addFriends/:email', (req, res, next) =>{
const email = req.params.email;
UserSchema.find({email: email}, { "friendsPending.emailSender": 1, _id : 0}, (err, data) =>{
if(err){
res.status(404).send(err);
}else{
res.status(200).send(data[0]);
}
});
});
This is my call in Postman : /users/addFriends?email=a
When running this call, server returns 404 status. It happened even when i tested it with another get call.
Any comments are appriciated, however other POST and GET calls work normally (they use body not parameters). Thanks
router.post('/friends/:email', (req, res, next) => {})
since you're creating a friend association. – nicholaswminnext
parameter in your function is not necessary. it's for pass router to other matchable routers. – Ali