首页 > 解决方案 > 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));
});

标签: javascriptnode.jsexpressroutesruntime-error

解决方案


You are confused in places 'req' and 'res', they should be the other way around:

exerciseRouter.post('/update/:id', (req, res) => {

推荐阅读