Validating models in Node Js using Indicative

Data validation is the key point of writing applications,as it is always important to make sure the data you are collecting is valid upto some extent.

Validating models/data models in nodejs is pretty simple as there are ton of packages which can help in doing same but my favourite is Indicative.


Indicative is a beautiful Laravel inspired validation library for Nodejs with powerful promises.

It makes validating data models really simple with set of expressive rules.


npm install indicative  


Let's start with a simple example to get taste of how indicative works.


 var rules = {
    'name' : 'required|alpha'

Rules are a set of objects defining validation rules seperated with | (pipe).


var values = {  
  'name': 'johny123'

Above we have some sample data we are planning to validate against our
defined set of rules.

Finally we are going to use indicative to run validation using our dummy data and defined set of rules.

// requiring indicative package
var validator = require('indicative');  
// initializing it


Indicative returns a promise with success or error depending whether
validation has passed or failed.

In our case it would have been failed becuase johny123 is not a valid alpha string.

Try is yourself