Answers for "express validator check vs body"


express validator check vs body

Same as check([fields, message]), but only checking req.body.
Posted by: Guest on March-02-2021


// of the initial code omitted for simplicity.
const { body, validationResult } = require('express-validator');'/user', [
  // username must be an email
  // password must be at least 5 chars long
  body('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));
Posted by: Guest on July-18-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language