I'm trying to use express-validator, but none of it's functions work. I'm not getting any errors either.
Example:
const check = require('express-validator/check').check;
router.post('/register', check('someRandomName').exists(), (req, res) => userController.register(req, res));
express-validator always allows it, even if I don't have someRandomName in the req. 
I also tried using body instead of check, but the result was the same.
The check returns a validation chain which you suppose to validate result in your req after it using validationResult, so something like this:
const {check , validationResult}  = require('express-validator/check');
router.post('/register', check('someRandomName').exists(), (req, res) => {
       var err = validationResult(req);
       if (!err.isEmpty()) {
           console.log(err.mapped())
           // you stop here 
       } else {
           // you pass req and res on to your controller
       }
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With