Skip to content

Latest commit

 

History

History
30 lines (26 loc) · 557 Bytes

express-validator.md

File metadata and controls

30 lines (26 loc) · 557 Bytes

express-validator

npm i express-validator
const { check } = require('express-validator');

router.post(
  '/signup',
  [
    check('name').not().isEmpty(),
    check('email')
      .normalizeEmail() // [email protected] => [email protected]
      .isEmail(),
    check('password').isLength({ min: 6 }),
  ],
  usersController.signup
);
const signup = (req, res, next) => {
  const errors = validationResult(req);
  if (!errors.isEmpty()) {
    throw new HttpError('Invalid inputs passed, please check your data.', 422);
  }
};