Express validator usage
Express validator middleware is used to validate user input in a request
Routine
is also fully compatible with this middleware
example
const Routine = require('routinejs')
const { body, validationResult } = require('express-validator')
const app = new Routine({
enableBodyParsing: true,
catchErrors: true,
})
app.post(
'/user',
body('username').isEmail(),
body('password').isLength({ min: 5 }),
(req, res) => {
const errors = validationResult(req)
if (!errors.isEmpty()) {
return res.status(400).json({ errors: errors.array() })
}
}
)
app.listen() //:8080