title: How to implement validation in a separate file using express-validator
body: <p>I am trying to use express-validator to validate the req.body before sending a post request to insert data to postgres.</p>
  <p>I have a route file, controller file and I want to carryout validation in a file called validate.js. Meanwhile, I have installed express-validator and in my server.js I have imported it. Other resources I come across seem to implement the validation in the function that contains the logic for inserting the data.</p>
  <pre class="lang-js prettyprint-override"><code>//server.js
  ....
  import expressValidator from 'express-validator';
  
  ...
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(expressValidator);
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>//route.js
  import express from 'express';
  import usersController from './controller';
  
  const router = express.Router();
  
  router.post('/createuser', usersController.createUser);
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>//controller.js
  createUser(req, res){
    // ...
    const { firstName, lastName, email, password } = req.body;
    //code to insert user details to the database
  }
  
  </code></pre>
  <pre class="lang-js prettyprint-override"><code>//validator.js
  import { check } from 'express-validator/check';
  
  module.exports = [check('email').isEmail()];
  </code></pre>
  <p>I expect to implemet the validation in a file called validator.js to, say, validate the email before inserting to the database</p>