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
  // 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() });

    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.

1 Answers

Leibale Eidelman On Best Solutions

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.