I\'m getting error req.checkBody is not a function thought I\'ve included express-validator and body-parser..
Here is my code
var express = require(\'exp
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var expressValidator = require('express-validator');
app.use(bodyParser.urlencoded({ extended: true }));
app.use(expressValidator()); //this line to be affffded
app.get('/',function(req,res){
res.sendFile(__dirname +'/index.html')
});
app.post('/',function(req,res){
req.checkBody("name", "Invalid company").notEmpty();
var errors = req.validationErrors();
if (errors) {
res.status(400).send({ "message": "Missing parameter" });
// res.send('There have been validation errors: ' + util.inspect(errors), 400);
return;
}
var company = new companySchema(req.body);
company.save(function(err) {
if (err) {
if (err.code === 11000) {
return res.status(409).send({ "message": "Company already exist!" });
}
return res.status(400).send({ "message": "Server Error!", "err": err });
}
return res.status(200).send({ "message": "New company has added!" });
});
});