尝试使用Node运行测试Neo4J文件时Error.captureStackTrace

时间:2017-03-13 14:42:25

标签: javascript node.js neo4j

我尝试使用Node运行Neo4j的测试文件,我按照此处的说明操作:https://neo4j.com/developer/

在我的app项目中,我安装了neo4j-driverneo4j(通过yarn)并创建了测试neo4j.js文件。

然后运行neo4j社区版服务器。

// npm install --save neo4j
var neo4j = require('neo4j');
var db = new neo4j.GraphDatabase('http://neo4j:<password>@localhost:7474');

var insertQuery = 
  "UNWIND {pairs} as pair \
   MERGE (p1:Person {name:pair[0]}) \
   MERGE (p2:Person {name:pair[1]}) \
   MERGE (p1)-[:KNOWS]-(p2)";

var foafQuery = 
 "MATCH (person:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf) \
  WHERE person.name = {name} \
   AND NOT (person)-[:KNOWS]-(foaf) \
  RETURN foaf.name AS name";

var commonFriendsQuery =
"MATCH (user:Person)-[:KNOWS]-(friend)-[:KNOWS]-(foaf:Person) \
 WHERE user.name = {name1} AND foaf.name = {name2} \
 RETURN friend.name AS friend";

var connectingPathsQuery =
"MATCH path = shortestPath((p1:Person)-[:KNOWS*..6]-(p2:Person)) \
 WHERE p1.name = {name1} AND p2.name = {name2} \
 RETURN [n IN nodes(path) | n.name] as names";

var data = [["Jim","Mike"],["Jim","Billy"],["Anna","Jim"],
            ["Anna","Mike"],["Sally","Anna"],["Joe","Sally"],
            ["Joe","Bob"],["Bob","Sally"]];

function query(query, params, column, cb) {
    function callback(err, results) {
        if (err || !results) throw err;
        if (!column) cb(results)
        else results.forEach(function(row) { cb(row[column]) });
    };
    db.cypher({ query: query, params: params}, callback);
}

query(insertQuery, {pairs: data}, null, function () {
    query(foafQuery, {name: "Joe"},"name", console.log); 
    query(commonFriendsQuery, {name1: "Joe", name2:"Sally"},"friend",console.log);
    query(connectingPathsQuery, {name1: "Joe", name2:"Billy"}, "names", 
          function(res) { console.log(res)});
});

当我转到目录并运行node neo4j.js时,我收到以下错误:

enter image description here

我也尝试将第3行更改为:var db = new neo4j.GraphDatabase('http://neo4j:neo4j@localhost:7474');

1 个答案:

答案 0 :(得分:0)

这是issuenode-neo4j在Node.js v7上运行。请注意,您使用的软件包不是官方驱动程序,它位于npm注册表中neo4j-driver