Reputation: 991
I'm currently learning express-validator, in the docs there is an example like:
const { check, validationResult } = require('express-validator/check');
app.post('/user', [
// username must be an email
check('username').isEmail(),
// password must be at least 5 chars long
check('password').isLength({ min: 5 })
], (req, res) => {
// Finds the validation errors in this request and wraps them in an object with handy functions
const errors = validationResult(req);
if (!errors.isEmpty()) {
return res.status(422).json({ errors: errors.array() });
}
User.create({
username: req.body.username,
password: req.body.password
}).then(user => res.json(user));
});
So, I don't understand why is ther an array passed to the post
method.
And, can you tell me how can I learn more about it?
Thank you in advance.
Upvotes: 1
Views: 120
Reputation: 3194
As you can read in expressjs docs, passing array is the same as passing multiple arguments. This has been done to enable reuse of multiple middlewares.
Upvotes: 3