Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 无法运行nools_Node.js_Express_Nools - Fatal编程技术网

Node.js 无法运行nools

Node.js 无法运行nools,node.js,express,nools,Node.js,Express,Nools,嗨,我正在node.js中研究nools。运行此程序时发生错误: 抛出新错误(“无效表达式“+”表达式+”))无效表达式“m.text=~/^hello(\s*world)?$/”请帮助解决此问题 这是我的代码: Server.js var express = require("express"); var bodyParser = require("body-parser"); var app = ex

嗨,我正在node.js中研究nools。运行此程序时发生错误:

抛出新错误(“无效表达式“+”表达式+”))无效表达式“m.text=~/^hello(\s*world)?$/”请帮助解决此问题

这是我的代码:

Server.js

var express        =         require("express");
var bodyParser     =         require("body-parser");
var app            =         express();

app.use(bodyParser.urlencoded({
    extended: true
}));

var index = 0;

var nools = require("nools");

var flow = nools.compile(__dirname + "/server/rules.nools");
var Message = flow.getDefined("message");
var session = flow.getSession();

session.matchUntilHalt().then(
    function() {
        //all done!
        console.log("All done!");
    },
    function(err) {
        console.log("Error matchUntilHalt()", err.stack);
    }
);

app.post('/fact', function(req, res) {
    var key = req.body.key;

    console.log("\n" + ++index + " New fact", key);

    var newMsg = new Message(key);

    session.assert(newMsg);

    res.end("All OK");
});

app.get('/', function(req, res) {
    res.end("Watsup! Its " + new Date());
});

app.listen(4000, function() {
    console.log("Started up!");
});
罗尔斯,诺尔斯

define Message {
    text: '',
    constructor: function(message) {
        this.text = message;
    }
}

//find any message that starts with hello
rule Hello {
    when {
        m: Message m.text = ~/^hello(\s*world)?$/;
    }
    then {
        console.log("Hello rule fired.");
    }
}

//find all messages then end in goodbye
rule Goodbye {
    when {
        m: Message m.text = ~/.*goodbye$/;
    }
    then {
        console.log("Goodbye rule fired.");
    }
}

define Client {
    age: 0,
    constructor: function(age) {
        this.age = age;
    }
}

rule CheckAge {
    when {
        // Multiple conditions in same rule
        c: Client c.age > 30 && c.age < 65
    }
    then {
        console.log("Eligible for loan");
    }
}
定义消息{
文本:“”,
构造函数:函数(消息){
this.text=消息;
}
}
//查找任何以hello开头的邮件
规则你好{
什么时候{
m:Message m.text=~/^hello(\s*world)?$/;
}
然后{
log(“Hello-rule-fired.”);
}
}
//找到所有消息,然后以“再见”结尾
规则再见{
什么时候{
m:Message m.text=~/.*再见$/;
}
然后{
log(“触发了再见规则”);
}
}
定义客户端{
年龄:0,,
构造函数:函数(年龄){
这个。年龄=年龄;
}
}
规则检查{
什么时候{
//同一规则中的多个条件
c:客户c.age>30岁和c.age<65岁
}
然后{
console.log(“符合贷款条件”);
}
}
您的错误如下:

//find any message that starts with hello
rule Hello {
    when {
        m: Message m.text = ~/^hello(\s*world)?$/;
    }
    then {
        console.log("Hello rule fired.");
    }
}

//find all messages then end in goodbye
rule Goodbye {
    when {
        m: Message m.text = ~/.*goodbye$/;
    }
    then {
        console.log("Goodbye rule fired.");
    }
}
要使用的表达式在=和~之间有一个空格

m: Message m.text = ~/.*goodbye$/;
m: Message m.text = ~/^hello(\s*world)?$/;
改为:

m: Message m.text =~ /^hello(\s*world)?$/;


它会起作用的。

nools不是生命的终结吗?
m: Message m.text =~ /.*goodbye$/;