0

这个函数有什么问题(表达 4.16.0,TypeError: req.assert is not a function):

userController.signupPost = function(req, res, next) {
console.log(req.body);
var express=require('express');
var validator = require('express-validator');
var app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
app.use(validator())
req.assert('name', 'Name cannot be blank').notEmpty();
req.assert('email', 'Email is not valid').isEmail();
req.assert('email', 'Email cannot be blank').notEmpty();
req.assert('password', 'Password must be at least 4 characters long').len(4);
req.sanitize('email').normalizeEmail({ remove_dots: false });
}
4

1 回答 1

0

请尝试用 checkBody 替换 assert。

req.checkBody('name', 'Name cannot be blank').notEmpty().

像这样做。

于 2018-07-26T11:10:35.783 回答