Check is not defined on express-validator using routes V4 Check is not defined on express-validator using routes V4 express express

Check is not defined on express-validator using routes V4


express-validator embraces ES6, and it supports Node 6+.
As you stated in the comments, you're using Node 8.4.0, then you're good with it.

You're importing the functions wrong, as you must bind the functions from the default export. Or use destructuring, which is a lot cooler:

const { check, validationResult } = require('express-validator/check');// or:const check = require('express-validator/check').check;const validationResult = require('express-validator/check').validationResult;

Also, remember to check the usage section :)


The syntax of app.use(expressValidator()) is the legacy syntax of express-validator. See https://express-validator.github.io/docs/legacy-api.html for details.

It's recommended that you upgrade your code and syntax to the newer version, where check is a middleware on its own (example), instead of a member function of req.

However, if you don't want to rewrite the whole validator part of your code, then all you need to do is in your package.json make the version of express-validator to be express-validator:~3 (instead of ^6... of whatever that is) and do npm i. That should fix it.


Try removing the '/check' part from your require statement to have

var check  = require('express-validator');var validationResult = require('express-validator');