TypeError: req.checkBody is not a function

前端 未结 4 1783
花落未央
花落未央 2020-12-18 23:50

I\'m trying to implement some validation in a sign up system, but I get the error:

     TypeError: req.checkBody is not a function

from th

相关标签:
4条回答
  • 2020-12-19 00:15

    Same as in the above answer, after installing express-validator, adding

    server.use(expressValidator()); 
    

    under

    const express=require("express"); 
    

    and

    const server=express(); 
    

    solved my problem.

    0 讨论(0)
  • 2020-12-19 00:15

    With express-validator 6 you will have to do the following:

    import

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

    validation

    body('username').isEmail()
    body('password').isLength({ min: 5 })
    

    errors

    const errors = validationResult(req);
    
    0 讨论(0)
  • 2020-12-19 00:23

    You need to install express-validator using below command

    npm install express-validator
    

    then add

    var expressValidator = require('express-validator');
    api.use(expressValidator())
    

    immediately after

    var api = express.Router();
    

    See TypeError: req.checkBody is not a function including bodyparser and expressvalidator module for more details

    0 讨论(0)
  • 2020-12-19 00:30

    I encountered the same problem, I found out that the problem was from the current version of express_validator. I had to degrade to "express-validator": "5.3.1", and it worked for me. I think the need to fix the issue.

    0 讨论(0)
提交回复
热议问题