expressValidator is not a function even it specifies middleware must be function

> const {body} = require('express-validator');
var validate=(method) =>{
        case 'userRegistered':{
            return [
                body('username','Username doesnot exists').exists(),
                body('email','Invalid Email').exists().isEmail(),
                body('name','Invalid Email').optional(),
                body('password','password must be atleast 8 characters').exists().isLength({min:8,max:15}),
                body('Image','please upload your Image').exists(),

//route Handler

const errors = validationResult(req)
    res.status(422).json({errors:errors.array() });
await userRegistered(req.body,req.file.path,"client",res);
> const expressValidator = require('express-validator');
  const bodyParser = require('body-parser');

// I use express validation as middleware in my REST API but got an error of
// app.use(expressValidator());

TypeError: expressValidator is not a function

109 thoughts on “expressValidator is not a function even it specifies middleware must be function”