1
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');
});

Error:

/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.
cybersam
  • 63,203
  • 6
  • 53
  • 76
chethan
  • 13
  • 3

1 Answers1

0

As @Molda indicated, if your neo4j server has authentication enabled (which is true by default), then you need to provide authentication info (username and password) with your REST requests.

The easiest way to do that is to include the authentication info in the base URL you use to communicate with the neo4j server. For example, if your username is "neo4j" and password is "secret", then your db assignment statement should be:

db = new neo4j('http://neo4j:secret@localhost:7474');
cybersam
  • 63,203
  • 6
  • 53
  • 76