gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'express-validator#contexts' of undefined

转载 作者:行者123 更新时间:2023-12-04 07:44:25 27 4
gpt4 key购买 nike

我正在尝试使用 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

任何人都可以为我解释这个错误并帮助我修复它?

最佳答案

根据documentation , validationResult 函数需要一个参数:

常量错误 = validationResult(req)

关于javascript - 类型错误 : Cannot read property 'express-validator#contexts' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67269061/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com