Create a CRUD App with Node and MongoDB

Validation Error Messages

When giving a form to users, we always need to handle errors in input. We want to be sure that the information we get from them is pristine.

We'll use express-validator, a great package to validate different inputs, whether it comes from a form, url parameters, or JSON.

Install it with:

npm install express-validator

Configure it using the following line. Note: It has to be placed immediately after the express.bodyParser() configuration.

app.use(express.bodyParser());
app.use(expressValidator()); // this line must be immediately after express.bodyParser()!