-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
43 lines (37 loc) · 762 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const fastify = require("fastify");
const app = fastify();
const { Engine } = require("json-rules-engine");
let engine = new Engine();
engine.addRule({
conditions: {
all: [
{
fact: "temperature",
operator: "equal",
value: 100
}
]
},
onSuccess(){
console.log('on success called')
},
onFailure(){
console.log('on failure called')
},
event: {
type: "message",
params: {
data: "hello-world!"
}
}
});
const facts = { temperature: 100 };
engine
.run(facts)
.then(results => {
results.events.map(event => console.log('value', event.params.data));
})
.catch((error)=> console.log('err is', error));
app.listen(3000, () => {
console.log("Your app is running");
});