Neo4jError:由于身份验证失败,客户端未经授权

问题描述 投票:1回答:1

我是neo4j的新手。我正在使用javascript驱动程序。需要知道我做错了什么。我附加了代码段。我错过了什么吗?请指导我。

app.js

var express = require('express');
var bodyParser = require('body-parser');
var neo4j = require('neo4j-driver').v1;
var app = express();
app.use(bodyParser.json());

var driver = neo4j.driver('bolt://localhost', neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();

session
.run('MERGE (alice:Person {name : {nameParam} }) RETURN alice.name AS name', {nameParam: 'Alice'})
.subscribe({
    onNext: function (record) {
        console.log(record.get('name'));
    },
    onCompleted: function () {
        session.close();
    },
    onError: function (error) {
        console.log(error);
    }
});

/*   Start the express App and listen on port 8080 */
  var initServer = function () {

    var server = app.listen(8080);
     console.log('info', '*********** Application Server is listening on Port 8080 ***********');

 };

 initServer();

错误:img

neo4j
1个回答
0
投票

我今天早些时候简要地碰到了同样的问题。但后来我记得当我早些时候启动neo4j服务器时,我已经从浏览器导航到http://localhost:7474并使用默认凭据username = neo4j和password = neo4j登录,然后在我继续之前提示我创建一个新密码。

我的预感是你可能没有改变你需要的默认密码。之后,您应该没有身份验证问题。使用下面的简短程序检查您是否良好。创建一个文件index.js并添加:

const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "YOUR_NEW_PASSWORD"));
const session = driver.session();

const personName = 'Alice';
session.run(
  'CREATE (a:Person {name: $name}) RETURN a',
  {name: personName})
.then(result => {
  session.close();

  const singleRecord = result.records[0];
  const node = singleRecord.get(0);

  console.log(node.properties.name);

  // on application exit:
  driver.close();
})
.catch(error => console.log(error));

使用nodejs,只需从命令提示符执行:

node index.js

您应该在命令行上看到输出“Alice”

© www.soinside.com 2019 - 2024. All rights reserved.