Parsley is a JavaScript library, that can work with both jQuery or Zepto, designed to validate forms easily. It is built with UX concerns in mind and tries to simplify details for the user.
Is this what you're looking for?
Answer from Diego Cardozo on Stack OverflowVideos
They are used for different scenarios:
validatoris a library to validate any kind of object and it's not associated with any framework.express-validatorusesvalidatorlibrary to validateexpressjsroutes. Basically you can validate express routes out of the box using validator lib.
In my honest opinion you can easily create your own validator middleware. Specially if you are new to Node.js it will help you to understand how middlewares work. If you are not interested on that and you have an express application feel free to use express-validator
Also I really recommend JOI as a validator lib https://github.com/hapijs/joi it's simple and it works well.
Here is an example of a middleware (I have not tested)
const Joi = require('joi')
module.exports = function validate(joiSchema) {
return async (req, res, next) => {
const result = Joi.validate(req.body, joiSchema, {
allowUnknown: true,
abortEarly: false
})
if (result.error) {
throw new result.error
}
await next()
}
}
// express route
router.post(
'/create',
validateMiddleware({
body: {
body: { firstName: Joi.string(), lastName: Joi.string() }
}
}),
(req, res, next) => {
// your logic
})
Express-validator is used as middleware, the idea with express-validator is to check bad input before it reaches your controller.
Now, if you are using validator, you can make your own validation function in which you will simply pass the data and it will tell if the input is in accordance to it (Just like checking an Email, here you can have a function, which will check if input given to it is a function or not).
In case you are using Services in your structure, then you can use validator as I feel it's easy and of more control than express-validator
ยป npm install validator