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

Problem

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

Solution

Okay, I'll answer to myself.

I found this module, really useful. https://github.com/chriso/node-validator

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

http://pastebin.com/Bw0qdbu1

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

Discussion

There is currently no discussion for this recipe.

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