express-validator返回错误数组,而不是“ post”请求上的有效req.body

时间:2020-07-23 18:17:30

标签: javascript node.js express express-validator

当我使用express-validator测试路线时,它返回错误数组而不是主体参数,似乎代码是正确的。

这是我的用户的路由文件

const express= require('express');
const router =  express.Router();
const {check, validationResult} = require('express-validator')

//@route  POST api/users
//@desc   Register User
//@access Public 

router.post('/' ,[
    check('name','name is required').not().isEmpty(),
    check('email','please enter a valid email').isEmail(),
    check('password','please enter a password with 6 or more').isLength({min:6})

    ] ,(req,res) =>{            
        const err = validationResult(req);
        if(!err.isEmpty()){
            return res.status(400).json({errors:err.array()})
        }       
}); 

module.exports = router

这是我的路线https:// localhost:5000 / api / users

的结果

Testing the route with RESTClient firefox extension also tested with postman

0 个答案:

没有答案