Skip to content

Instantly share code, notes, and snippets.

@poorcoder
poorcoder / gist:1474851
Created December 14, 2011 01:48
Bind node-validator to req
/*
* This binds the node-validator library to the req object so that
* the validation / sanitization methods can be called on parameter
* names rather than the actual strings.
*
* 1. Be sure to include `req.mixinParams()` as middleware to merge
* query string, body and named parameters into `req.params`
*
* 2. To validate parameters, use `req.check(param_name, [err_message])`
* e.g. req.check('param1').len(1, 6).isInt();