Nodejs sanitize
Request and Mongo
We need validation from user input basically.
Get data from req.body, req.params etc…
In Nodejs, validator is covered html sanitization.
If you use Mongoose and save, update not using insert code directly,
you don’t need to be care about mongo sanitization.
To use validator in nodejs project, you use following command.
npm install validator
Sample
I create simple wrapper to return sanitization str.
var validator = require('validator'); var escape = function(str) { if (str == null) return null; return validator.escape(str); }; module.exports = { escape : escape };