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.
答案 0 :(得分:0)
正如@Molda所指出的,如果您的neo4j服务器启用了authentication(默认情况下为true),那么您需要为REST请求提供身份验证信息(用户名和密码)。
最简单的方法是在用于与neo4j服务器通信的基本URL中包含身份验证信息。例如,如果您的用户名为“neo4j”且密码为“secret”,那么您的db
转让声明应为:
db = new neo4j('http://neo4j:secret@localhost:7474');