Hemanth's Scribes

node

Node Rules - Business Rules Engine

Author Photo

Hemanth HM

Thumbnail

node-rules is a light weight forward chaining Rule Engine.

Install

npm install —save node-rules

Create a Rule

var rule = {
  condition: function(R) {
    R.when(this.transactionTotal < 500);
  },
  consequence: function(R) {
    this.result = false;
    this.reason = "Transaction blocked - less than 500";
    R.stop();
  }
};

## Create a Fact
javascript
var fact = {
  name: "user4",
  transactionTotal: 400
};

## Execute
javascript
var R = new RuleEngine();
R.register(rule);
R.execute(fact, function(data) {
  console.log(data.result ? "Valid" : data.reason);
});

Thanks to Mithun Satheesh for this module!

#node#business-logic
Author Photo

About Hemanth HM

Hemanth HM is a Sr. Machine Learning Manager at PayPal, Google Developer Expert, TC39 delegate, FOSS advocate, and community leader with a passion for programming, AI, and open-source contributions.