此函数有什么问题(express 4.16.0,TypeError:req.assert不是函数):
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 });
}
答案 0 :(得分:0)
请尝试将assert替换为checkBody。
req.checkBody('name', 'Name cannot be blank').notEmpty().
这样做吧。