Helper for check all params node.js - sails - express


I want to check my params in my controllers. For the moment, I'm doing like that:

create: function (req, res) {
    if(req.params.label && req.params.password){
     // do stuff

But I want to do this more quickly. I'm wondering if there is no tools which already exist.

I want to do things like that:

create: function (req, res) {
    checkParams({label: {empty: false}, password: {empty: false}}, function(err){
        // Do stuff

Do you know something which could help me?

Thank you.

Problem courtesy of: Vadorequest


Okay, I'll answer to myself.

I found this module, really useful.

And I wrote, by my own (and with a little help from here =D) a little helper for manage validations:

Thanks for the help ;) Two samples are available in the file, I'm using sails.js. But it can be used with anything, you need the validator package, obviously.

npm install validator --save

Don't forget to import validator at the start of file.

var validator = require('../services/validator');
Solution courtesy of: Vadorequest


There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.