What is express-validator?

Bruce Gust
Bruce Gust used Ask the Experts™
I'm going through a Node tutorial and I'm at the point where I'm working with "express-validator."

According to the docs, "express-validator" is "...a set of express.js middlewares that wraps validator.js validator and sanitizer functions."

Easy enough, but I want to better understand that definition and it's bugging me that I've never installed the "validator.js" library.

Here's what I understand:

Middleware acts as a bridge between two applications. In the context of Node, Express is middleware specifically in the way it intercepts and interacts with the request and the response objects that are coming from the DOM (feel free to stop me at any time if I'm not accurate).

A "wrapper," according to https://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_html_wrap_element, is something that's going to "wrap" around a div...

So, going back to the original definition, it looks as though Express-Validator is wrapping around the "validator.js" library and making it more intuitive to use.

But where does "validator.js" come from? I've never installed it, so how did that become use-able?

And then when I look at the example of the Jquery "wrap" method (https://www.w3schools.com/jquery/html_wrap.asp)...

How does express-validator "wrap" around validator.js?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Analyst Developer
Distinguished Expert 2018
First, the validator.js refers to this repo https://github.com/validatorjs/validator.js what is a library of string validators and sanitizers.

validator.js is one of the express-validator dependencies & express-validator uses validator.js to validate expressJS routes and it’s mainly built for express js applications which makes this library more niche and provides out of box custom validation and sanitization.

IMO the wrap meaning in this context is built-on-top-of.

Here's a nice detailed tutorial about it.
Take a look also at this answer
Bruce GustPHP Developer


Zakaria! Your answer reinforced my intuition, but I wanted to confirm it. Let me explain back to you what you just said...

express-validator includes validator.js. validator.js is a library and you will find that library within express-validator. And while wrap is a a JQuery function, in this context it's not so much that it's "wrapping" around a piece of HTML like I referenced in the example above as much as it's referring to the way in which express-validator is built on top of the validator.js library and making it easier to implement.

Sound right?
Zakaria AcharkiAnalyst Developer
Distinguished Expert 2018

Yes Bruce, right as you said.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial