express-validation throws an error: Error('Please provide a validation schema')

Viewed 1376

I am new to Node.js. I wanted to add a simple validation for one of the form's field just to test the validation offered in Express. I followed the steps at https://www.npmjs.com/package/express-validation

I used express-validation middleware. I installed the appropriate modules(express-validation and joi).

Then I have added a folder "validation" and file "edit" with the following content:

var Joi = require('joi');

module.exports = {
    body: {
        title: Joi.string().required()
    }
};

In the route that handles the post from the form I have added the appropriate parameter:

router.post('/', validate(validation.edit), function(req, res, next)

and saved the middleware and file with validation rule to the vars:

var validate = require('express-validation');
var validation = require('../validation/edit.js');

When I run the app it throws an error: Error('Please provide a validation schema').

So, I wonder what validation schema is required and where I suppose to add it?

1 Answers
Related