首页 > 解决方案 > Neo4jError: The client is unauthorized due to authentication failure

问题描述

I am newbie to neo4j. I am using javascript driver . Need to know what i am doing wrong . I am attaching code snippet . Am I missing something ? Please guide me.

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();

error : img

标签: neo4j

解决方案


I briefly bumped into the same problem earlier today. But then I remembered that when I started the neo4j server earlier, I had navigated to http://localhost:7474 from the browser and signed in using the default credentials username=neo4j and password=neo4j, which then prompted me to create a new password before I could proceed.

My hunch is that you probably have not changed the default password, which you need to. After that, you should have no problem with authentication. Use the short program below you check if you are good. Create a file index.js and add this:

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));

The using nodejs, simply execute this from the command prompt:

node index.js

You should see the output "Alice" on the command line


推荐阅读