title: How can I solve TypeError: express-validator is not a function
body: <p>I'am using express-validator version 6.4.0. I am getting this error while running the server. I've tried to use custom validation and have created separate files for validator, controller and routes.</p>
  
  <p>Here is the main server file "index.js"</p>
  
  <pre><code>const express = require('express');
  const bodyParser = require('body-parser');
  const cookieParser = require('cookie-parser');
  const {expressValidator} = require('express-validator');
  const db = require('./models');
  
  const app = express();
  
  db.sequelize.sync({force: true}).then(() =&gt; { console.log("Connected to DB") }).catch((err) =&gt; {console.log(err)});
  
  app.use(bodyParser.urlencoded({extended: true}));
  app.use(bodyParser.json());
  app.use(cookieParser());
  
  app.use(expressValidator());
  
  require('./routes/user.routes')(app);
  </code></pre>
  
  <p>My validator file has two functions one for checking validation and other for returning response based on validation "user.validator.js"</p>
  
  <pre><code>const { check, validationResult } = require('express-validator');
  
  const checkValidation = (method) =&gt; {
      switch (method) {
          case "create": {
              return [
                  check("first_name").exists().withMessage("It is mandatory to enter your first name"),
                  check("last_name").exists().withMessage("It is mandatory to enter your last name"),
                  check("email").exists().withMessage("It is mandatory to enter email")
                  .isEmail().withMessage("The email must be in correct format as foo@bar.com"),
                  check("password").exists().withMessage("It is mandatory to enter password")
                  .isLength({ min: 6 }).withMessage("Password must be at least 6 characters in length"),
                  check("role").exists().withMessage("It is mandatory to enter role")
                  .isInt().withMessage("Role must be a number")
              ];
          }
      }
  }
  
  const validate = (req, res, next) =&gt; {
      const errors = validationResult(req);
  
      if (errors.isEmpty()) {
          return next();
      }
  
      const extractedErrors = [];
      errors.array().map(err =&gt; extractedErrors.push({ [err.param]: err.msg }))
  
      return res.status(422).json({
          errors: extractedErrors,
      });
  }
  
  module.exports = {
      checkValidation,
      validate,
  };
  
  </code></pre>
  
  <p>Here is my only function in user.controller.js</p>
  
  <pre><code>exports.create = (req, res, next) =&gt; {
      try {
          console.log(req.body);
          return res.json(req.body);
      } catch (error) {
          return next(error);
      }
  }
  </code></pre>
  
  <p>This is the routes file "user.routes.js"</p>
  
  <pre><code>module.exports = app =&gt; {
      const user = require('../controllers/user.controller');
      const {checkValidation, validate } = require('../validators/user.validate');
      let router = require('express').Router();
  
      //route to create a new tutorial
      router.post('/', checkValidation('create'), validate(), user.create);
  
      app.use('/api/users', router);
  }
  </code></pre>