【发布时间】:2021-07-19 23:16:59
【问题描述】:
我正在尝试使用 express-validator 中间件 v6.10.1 来验证一些数据,但是当我使用 postman 对其进行测试时,结果出现了一些异常错误。
我的代码:
const { check, validationResult } = require('express-validator')
router.post('/', [
check('name', 'Required Field!').not().isEmpty(),
check('email', 'Required Field!').not().isEmpty(),
check('email', 'Not Valid Email Format!').isEmail(),
check('password', 'Required Field!').not().isEmpty(),
check('password', 'Password Must Contain At Least 10 Characters!').isLength({ min: 10 }),
check('type', 'Required Field!').not().isEmpty()
], (req, res) => {
const errors = validationResult()
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
res.send('users route...')
})
控制台中显示的错误:
TypeError: Cannot read property 'express-validator#contexts' of undefined
谁能为我解释这个错误并帮助我解决它?
【问题讨论】:
标签: javascript express postman express-validator