express-validator: express validator is not a function
I used express-validator for some of my projects, today when i installed it and i wanted to use it like this
const expressValidator = require('express-validator'); app.use(expressValidator);
i got the error “expressValidator is not a function” this is with version “6.1.1”
i installed version “5.3.1” i used before and it worked.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 23
- Comments: 28 (3 by maintainers)
With me it worked out that way:
Uninstall the current version: npm uninstall express-validator And install the older version: npm install express-validator@5.3.1
You can change or degrade the version by running this command in your root folder. npm install express-validatior@5.3.1–save-exact
No need to delete your node modules.
Yeah, that’s a breaking change with v6.0.0.
@studentofcoding
@gustavohenke - I would also like to see some kind of migration from 5.x to 6.x, as I’m in the same situation as @RMS21 where I can no longer use
app.use(expressValidator)great!!! Thank you!
Same issue brought me here but I’ve been able to resolve it, thanks to StackOverflow
Here’s my implementation. Remove:
app.use(expressValidator())Then:
But then I still have issues and I need help here
…the
console.log(errors);is returning undefined for values that I am checking for even though I can retrieve the values withreq.body.value.A basic screenshot below:
Or: link: https://express-validator.github.io/docs/ const {check, validationResult} = require(‘express-validator’);
});
/utils/error.js file: module.exports = {
send: (err, req, res, code = 400)=>{
}
};
I have this function error, uninstall the current version and go to v 5.3.1 and I get even more errors. what should I do ?