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