Closed TechRova closed 2 years ago
I am having the same problem :(
i'm too
@TechRova , hey did you manage to resolve this? Can you tell me which of the routes is failing?
Wrap your request paramater, i.e. body
, params
, query
, etc. in a Joi.object
to fix this. See how the validate()
function in /lib/index.js works to understand why.
Example solution for a simple route with an :echo
param:
Before
const { Joi, validate } = require("express-validation");
const validation = {
params: { message: Joi.string().required().min(2) },
};
router.get("/echo/:message", validate(validation), (req, res) =>
res.send(req.params.message),
);
After
const { Joi, validate } = require("express-validation");
const validation = {
params: Joi.object({ message: Joi.string().required().min(2) }),
};
router.get("/echo/:message", validate(validation), (req, res) =>
res.send(req.params.message),
);
I solved the problem by Replacing
import Joi from 'Joi'
with
import {Joi} from 'express-validation'
If this is still a problem, please try to golf all of that code down to a minimal reproduction. Chances are you'll figure out what the problem is as part of that exercise :)
I think this will help: https://github.com/AndrewKeig/express-validation/pull/160
When I call any route in my express server , I am getting this error
I cannot understand what happening ?
Please explain me ?
Even I can't add details to this question , since I have no clue !!
I cant find out where this error occurs since the error message not showing the exact location and the function
validateAsync
not found in the codeParamValidation.js
auth.route.js
Please help me ?