In my nodejs app to filter all input data I use express-validator. Something like this:
app.post('/', function (req, res) {
req.sanitize('login').xss();
req.sanitize('password').xss();
//etc.
});
So my view is as:
form(action='/', method='POST')
input(name='login', type='text')
input(name='password', type='password')
input(type='submit')
All works fine but if I omit login field for example:
form(action='/', method='POST')
input(name='login', type='text')
input(name='password', type='password')
input(type='submit')
then I get exception. Why doesn’t express-validator check param existing?
According to the documentation you’re using it wrong.
You’ll need to use req.assert to validate. req.sanitize is to sanitize input, like so: