javascript - NodeJs Error : res status is not a function
问题描述
I am logging the error "res.status is not a function" when using this route.
Any idea how to solve this?
Best regards!
exerciseRouter.post('/update/:id', (res, req) => {
Exercise.findById(req.id)
.then(exercise => {
exercise.username = req.body.username;
exercise.description = req.body.description;
exercise.duration = Number(req.body.duration);
exercise.date = _Date_.parse(req.body.date); exercise.save()
.then(() => res.json('Exercise updated!'))
.catch(err => res.status(400).json('Error: ' + err));
})
.catch(err => res.status(400).json('Error: ' + err));
});
解决方案
You are confused in places 'req' and 'res', they should be the other way around:
exerciseRouter.post('/update/:id', (req, res) => {
推荐阅读
- r - 在 R 中使用 ggplot2 覆盖散点图
- wordpress - Hilight JS not working with wordpress REST API and nuxtjs
- javascript - Anchor links can't affect two elements - is there a workaround to jump on both the title and text
- angular - Angular 9: Custom directive to access value of child text input
- javascript - I would like to add download functionality to my google apps script
- python - How to define my own continuous wavelet by using Python?
- python - Can someone help me I always get TypeError:Can't multiply sequence by non-int of type 'str'
- swift - Can I set a lag time in between touchesBegan in Swift?
- html - How do you select a random element out of list, in django template?
- angular - Unable to fetch ENV values from docker to Angular application