I\'m trying to install and use express-validator package. I\'ve installed the package version (6.0.0) and then in my server.js file the code is:
const bodyPa
//just pass the checking as middleware not in the callback
//see here I've just passed an array for checking as middleware
// as the middleware is an array therefore you can add multiple checks in the array
router.post("/", [check('email', "your custom error message").isEmail()], (req, res) => {
const errors = validationResult(req);
if (!errors.isEmpty()) {
res.render('errorPage', { errors: errors.array() });
//if api caller return res.status(422).json({ errors: errors.array() });
}
else{
//here everything is ok to proceed
res.render('successPage', { data });
//to api caller res.json({msg : "ok"})
}
})