I am using express-validator 5.2.0 in a expressjs app. I implemented the validaiton on a form data. But it does not capture the errors and gives empty errors object. When validation runs it shows the "no error" when I submit the empty form. It should follow the error path and should display the error.
var express = require('express');
var router = express.Router();
const { check, validationResult } = require('express-validator/check');
router.post('/register', [
check('firstName', 'First Name is required').isEmpty(),
check('lastName', 'Last Name is required').isEmpty(),
check('username', 'User Name is required').isEmpty(),
check('password', 'Password is required').isEmpty()
], (req, res, next)=>{
let errors = validationResult(req);
if (!errors.isEmpty()) {
console.log(errors.mapped());
console.log("errors")
return res.render('auth/register', { errors: errors.mapped() })
}else{
console.log('no errors')
return res.render('auth/login');
}