Video Course

Create a CRUD App with Node and MongoDB: Lesson 15 of 17

Validation Error Messages

Up Next

Editing Events

Autoplaying in 7 seconds!


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(expressValidator()); // this line must be immediately after express.bodyParser()!

Chris Sevilleja

156 posts

Co-founder of Slapping the keyboard until something good happens.