1

I'm using express-validator for making a Nodejs MongoDB application. I've installed the latest version of express-validator and Node but coming across "TypeError: expressValidator is not a function" as an error.

app.use(expressValidator({ errorFormatter: function(param, msg, value){ var namespace = param.split('.'), root = namespace.shift(), formParam = root; while(namespace.length){ formParam += '[' + namespace.shift() + ']'; } return { param: formParam, msg: msg, value: value }; } })); 
3
  • 1
    Seems like it's an issue in the way "express-validator" is called. Try to look at its documentation to see how they intend it to be used. Commented Dec 23, 2020 at 10:33
  • it's working with version @5.3.0 but not with the latest version @6.8.1. Commented Dec 23, 2020 at 11:01
  • How did you require express-validator package? And, what's expressValidator? Commented Dec 29, 2020 at 10:12

1 Answer 1

1

I guess you should not require express-validator as expressValidator.
According to express-validator V 6.10.0 docs you should do some thing like this

const { body, validationResult } = require("express-validator"); app.get('/signup',body('email').isEmail(), body('password').isLength({min: 5}), (req, res) => { const errors = validationResult(req); if (!errors.isEmpty()) { // handle error } // save user in DB }); 

we can also use custom validation for our fields checkout docs for more information.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.