-
-
Notifications
You must be signed in to change notification settings - Fork 623
Documentation issue #730
Copy link
Copy link
Closed
Labels
Description
In your documentation page https://express-validator.github.io/docs/running-imperatively.html you have a mistake:
The async function should be the closure function (in this case the request handler), and not the validate function itself. Example:
// can be reused by many routes
const validate = validations => {
return async (req, res, next) => {
await Promise.all(validations.map(validation => validation.run(req)));
const errors = validationResult(req);
if (errors.isEmpty()) {
return next();
}
res.status(422).json({ errors: errors.array() });
};
};
app.post('/api/create-user', validate([
body('email').isEmail(),
body('password').isLength({ min: 6 })
]), async (req, res, next) => {
// request is guaranteed to not have any validation errors.
const user = await User.create({ ... });
});Reactions are currently unavailable