How I use custom validation messages in Sails.js

When I started building a twitter clone in Sails.js, I noticed the model validation messages being thrown by the framework are not user friendly. So I wanted to provide custom validation messages but unfortunately, if I'm not mistaken, Sails doesn't currently support it because of the limitation of Anchor which is the validator used by Sails. If you'll check the source of Anchor, it's not passing a second parameter in the check() method from node-validator (the validator being wrapped and extended by Anchor) -


Because of this limitation, what I'm currently doing to use custom validation messages is to use node-validator directly. Here's an example snippet:

// UserController.js
var Validator = require('validator').Validator;

Validator.prototype.error = function (msg) {  
    return this;

Validator.prototype.getErrors = function () {  
    return this._errors;

module.exports = {

  store: function (req, res) {
    var username = req.param('username');
    var password = req.param('password');

    // validate inputs
    var validator = new Validator();
    validator.check(username, 'Username is required').notEmpty();
    validator.check(password, 'Password is required').notEmpty();

    var err = validator.getErrors();

    if (err.length > 0) {
        req.session.flash = {
            err: err

        return res.redirect('/user/create');

    // validation passes, do something...



If you know a better way on how to use custom validation messages in Sails.js, please share it in the comments section below. Thanks! :)