在 node-neo4j 中进行简单读取操作时出错

getting error on simple read operation in node-neo4j

var express = require('express');
var app = express();
var neo4j = require('node-neo4j');
db = new neo4j('http://localhost:7474');
db.readNode(2, function (err, node) {
    if (err) throw err;

    console.log(node.data);

    console.log(node._id);
});

app.listen(4000, function () {
    console.log('listening at 4000');
});

错误:

/home/embed/Documents/nodeneo/server.js:39
    if (err) throw err;
             ^

Error: HTTP Error 401 occurred while reading a node.
    at /home/embed/Documents/nodeneo/node_modules/node-neo4j/lib/main.js:173:15
    at Request.callback (/home/embed/Documents/nodeneo/node_modules/superagent/lib/node/index.js:748:3)
    at Request.<anonymous> (/home/embed/Documents/nodeneo/node_modules/superagent/lib/node/index.js:135:10)
    at emitOne (events.js:90:13)
    at Request.emit (events.js:182:7)
    at IncomingMessage.<anonymous> (/home/embed/Documents/nodeneo/node_modules/superagent/lib/node/index.js:938:12)
    at emitNone (events.js:85:20)
    at IncomingMessage.emit (events.js:179:7)
    at endReadableNT (_stream_readable.js:913:12)
    at _combinedTickCallback (node.js:377:13)
Program exited with status code of 1.

正如@Molda 指出的那样,如果您的 neo4j 服务器启用了 authentication(默认情况下为真),那么您需要在 REST 请求中提供身份验证信息(用户名和密码)。

最简单的方法是在用于与 neo4j 服务器通信的基础 URL 中包含身份验证信息。例如,如果您的用户名是 "neo4j",密码是 "secret",那么您的 db 赋值语句应该是:

db = new neo4j('http://neo4j:secret@localhost:7474');