title: Validating POST Params with Express-Validator
body: <p>I'm trying to build parameter validation into my Node/Express API using <a href="https://github.com/ctavan/express-validator" rel="nofollow">express-validator</a>. However, when I make a POST request with a missing field (name in this case) using the following curl command <code>curl -X POST -d "foo=bar" http://localhost:3000/collections/test</code>, the request still goes through successfully, skipping the validation. Below is my current code - any ideas as to why the validation is bypassed?</p>
  
  <pre><code>var util = require('util');
  var express = require('express');
  var mongoskin = require('mongoskin');
  var bodyParser = require('body-parser');
  var expressValidator = require('express-validator');
  
  var app = express();
  app.use(bodyParser());
  app.use(expressValidator());
  
  var db = mongoskin.db('mongodb://@localhost:27017/test', {safe:true})
  
  app.param('collectionName', function(req, res, next, collectionName){
    req.collection = db.collection(collectionName)
    return next()
  });
  
  app.post('/collections/:collectionName', function(req, res, next) {
    req.checkBody('name', 'name is required').notEmpty();
  
    req.collection.insert(req.body, {}, function(e, results){
      if (e) return next(e)
      res.send(results)
    });
  });
  
  app.listen(3000);
  </code></pre>