TypeError: expressValidator is not a function
While using version 6, you will encounter the following error:
TypeError: expressValidator is not a function
To avoid this issue you can use the previous version which is 5.3.1
TypeError: expressValidator is not a function
While using version 6, you will encounter the following error:
TypeError: expressValidator is not a function
To avoid this issue you can use the previous version which is 5.3.1
app.use(validator()) is not a function
var router = express.Router();
const { check, validationResult } = require('express-validator');
router.post('/register',
[
check('email', 'Email is not valid').isEmail(),
check('username', 'Username field is required').not().isEmpty(),
check('password', 'Password field is required').not().isEmpty())
],
function(req, res, next) {
// Check Errors
const errors = validationResult(req);
if (errors) {
console.log(errors);
res.render('register', { errors: errors.array() });
}
else {
console.log('No Errors');
res.render('dashboard', { message: 'Successful Registration.' });
}
});
// working express validator
// use a different method to Handle errors
app.use(validator()) is not a function
console.log(`error: ${err}`);
res.status(code).json({
error: err
});
// good error handling by express validation Pg 2
// make utils/app.js and write this code inside it
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us