All Projects → mithunsatheesh → Node Rules

mithunsatheesh / Node Rules

Licence: mit
Node-rules is a light weight forward chaining rule engine written in JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Node Rules

Json Rules Engine
A rules engine expressed in JSON
Stars: ✭ 1,159 (+140.96%)
Mutual labels:  rules, rule-engine, rules-engine, engine
Rulette
A pragmatic business rule management system
Stars: ✭ 91 (-81.08%)
Mutual labels:  rules, rule-engine, rules-engine
powerflows-dmn
Power Flows DMN - Powerful decisions and rules engine
Stars: ✭ 46 (-90.44%)
Mutual labels:  rules, rule-engine, rules-engine
Nrules
Rules engine for .NET, based on the Rete matching algorithm, with internal DSL in C#.
Stars: ✭ 1,003 (+108.52%)
Mutual labels:  rules, rule-engine, rules-engine
rools
A small rule engine for Node.
Stars: ✭ 118 (-75.47%)
Mutual labels:  rules, rule-engine, rules-engine
Nrules.language
Business rules language for NRules rules engine.
Stars: ✭ 55 (-88.57%)
Mutual labels:  rules, rules-engine
Rules
Generic Rules engine in golang
Stars: ✭ 96 (-80.04%)
Mutual labels:  rules, rules-engine
cs-expert-system-shell
C# implementation of an expert system shell
Stars: ✭ 34 (-92.93%)
Mutual labels:  rules, rule-engine
Rulerz
Powerful implementation of the Specification pattern in PHP
Stars: ✭ 827 (+71.93%)
Mutual labels:  rules, rules-engine
liteflow
Small but powerful rules engine,轻量强大优雅的规则引擎
Stars: ✭ 1,119 (+132.64%)
Mutual labels:  rule-engine, rules-engine
RulerZBundle
Symfony Bundle for RulerZ
Stars: ✭ 38 (-92.1%)
Mutual labels:  rules, rule-engine
ruledesigner
Rule Designer is the Eclipse-based development environment for ODM developers.
Stars: ✭ 14 (-97.09%)
Mutual labels:  rules, rule-engine
evrete
Evrete is a lightweight and intuitive Java rule engine.
Stars: ✭ 37 (-92.31%)
Mutual labels:  rule-engine, rules-engine
NiFi-Rule-engine-processor
Drools processor for Apache NiFi
Stars: ✭ 34 (-92.93%)
Mutual labels:  rule-engine, rules-engine
Roulette
A text/template based rules engine
Stars: ✭ 32 (-93.35%)
Mutual labels:  rules, rules-engine
Easy Rules
The simple, stupid rules engine for Java
Stars: ✭ 3,522 (+632.22%)
Mutual labels:  rule-engine, rules-engine
Rulebook
100% Java, Lambda Enabled, Lightweight Rules Engine with a Simple and Intuitive DSL
Stars: ✭ 562 (+16.84%)
Mutual labels:  rules, rules-engine
EngineX
Engine X - 实时AI智能决策引擎、规则引擎、风控引擎、数据流引擎。 通过可视化界面进行规则配置,无需繁琐开发,节约人力,提升效率,实时监控,减少错误率,随时调整; 支持规则集、评分卡、决策树,名单库管理、机器学习模型、三方数据接入、定制化开发等;
Stars: ✭ 369 (-23.28%)
Mutual labels:  rules, rule-engine
Drools
rules engine
Stars: ✭ 266 (-44.7%)
Mutual labels:  rules, engine
Gamification Engine
gamification-engine (gengine) is a framework for developing gamification features for your application
Stars: ✭ 286 (-40.54%)
Mutual labels:  rules-engine, engine

Build Status npm npm version Coverage Status npm downloads install size install size Known Vulnerabilities CDNJS

Node Rules

Node-rules is a light weight forward chaining Rule Engine, written in JavaScript for both browser and node.js environments.

Installation

npm install node-rules

Sample Screencast

Try This Out!

You can see this in action in a node.js environment using this RunKit example. If you are interested to use it in the browser, use this JSFiddle for a quick start.

Overview

Node-rules takes rules written in JSON friendly format as input. Once the rule engine is running with rules registered on it, you can feed it facts and the rules will be applied one by one to generate an outcome.

1. Defining a Rule

A rule will consist of a condition and its corresponding consequence. You can find the explanation for various mandatory and optional parameters of a rule in this wiki.

{
    "condition" : function(R) {
        R.when(this.transactionTotal < 500);
    },
    "consequence" : function(R) {
        this.result = false;
        R.stop();
    }
}

Here priority is an optional parameter which will be used to specify priority of a rule over other rules when there are multiple rules running. In the above rule R.when evaluates the condition expression and R.stop used to stop further processing of the fact as we have arrived at a result.

The functions R.stop, R.when, R.next, R.restart are part of the Flow Control API which allows user to control the Engine Flow. Read more about Flow Controls in wiki.

2. Defining a Fact

Facts are those input json values on which the rule engine applies its rule to obtain results. A fact can have multiple attributes as you decide.

A sample Fact may look like

{
  "name":"user4",
  "application":"MOB2",
  "transactionTotal":400,
  "cardType":"Credit Card",
}
3. Using the Rule Engine

The example below shows how to use the rule engine to apply a sample rule on a specific fact. Rules can be fed into the rule engine as Array of rules or as an individual rule object.

var RuleEngine = require("node-rules");

/* Creating Rule Engine instance */
var R = new RuleEngine();

/* Add a rule */
var rule = {
    "condition": function(R) {
        console.log(this);
        R.when(this.transactionTotal < 500);
    },
    "consequence": function(R) {
        this.result = false;
        this.reason = "The transaction was blocked as it was less than 500";
        R.stop();
    }
};

/* Register Rule */
R.register(rule);

/* Add a Fact with less than 500 as transaction, and this should be blocked */
var fact = {
    "name": "user4",
    "application": "MOB2",
    "transactionTotal": 400,
    "cardType": "Credit Card"
};

/* Check if the engine blocks it! */
R.execute(fact, function (data) {
    if (data.result) {
        console.log("Valid transaction");
    } else {
        console.log("Blocked Reason:" + data.reason);
    }
});
4. Controlling Rules running on the Rule Engine

If you are looking for ways to specify the order in which the rules get applied on a fact, it can be done via using the priority parameter. Read more about it in the Rule wiki. If you need to know about how to change priority of rules or remove add new rules to a Running Rule Engine, you may read more about it in Dynamic Control Wiki.

5. Exporting Rules to an external storage

To read more about storing rules running on the engine to an external DB, refer this wiki article.

Wiki

To read more about the Rule engine functions, please read the wiki here!. To find more examples of implementation please look in the examples folder.

Issues

Got issues with the implementation?. Feel free to open an issue here.

Licence

Node rules is distributed under the MIT License.

External References

Credits

The JSON friendly rule formats used in version 2.x.x of this module were initially based on the node module jools. The screencast image shown in this page is taken from nmotv.in which has a pretty nice article on how to use this module!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].