I have this simple node server (based on the documentation provided here - https://www.npmjs.com/package/neo4j-driver?activeTab=readme
const neo4j = require('neo4j-driver');
const driver = neo4j.driver('neo4j://localhost', neo4j.auth.basic('admin', 'admin12345'));
const session = driver.session({
database: 'neo4j',
defaultAccessMode: neo4j.session.WRITE
})
session
.run('MATCH (n) RETURN n')
.subscribe({
onKeys: keys => {
console.log(keys)
},
onNext: record => {
console.log(record)
},
onCompleted: () => {
session.close() // returns a Promise
},
onError: error => {
console.log(error)
}
})
I get this error
Neo4jError: Could not perform discovery. No routing servers available. Known routing table: RoutingTable[database=neo4j, expirationTime=0, currentTime=1678320189241, routers=[], readers=[], writers=[]]
at captureStacktrace (/Users/j/Development/Neo4j/server/node_modules/neo4j-driver-core/lib/result.js:611:17)
at new Result (/Users/j/Development/Neo4j/server/node_modules/neo4j-driver-core/lib/result.js:105:23)
at Session._run (/Users/j/Development/Neo4j/server/node_modules/neo4j-driver-core/lib/session.js:223:16)
at Session.run (/Users/j/Development/Neo4j/server/node_modules/neo4j-driver-core/lib/session.js:174:27)
at Object.<anonymous> (/Users/j/Development/Neo4j/server/neo.js:10:6)
at Module._compile (node:internal/modules/cjs/loader:1149:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1203:10)
at Module.load (node:internal/modules/cjs/loader:1027:32)
at Module._load (node:internal/modules/cjs/loader:868:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
constructor: [Function: Neo4jError] { isRetriable: [Function (anonymous)] },
code: 'ServiceUnavailable',
retriable: true,
[cause]: Neo4jError: Failed to connect to server. Please ensure that your database is listening on the correct host and port and that you have compatible encryption settings both on Neo4j server and driver. Note that the default encryption setting has changed in Neo4j 4.0. Caused by: connect ECONNREFUSED ::1:7687
at new Neo4jError (/Users/j/Development/j/Neo4j/server/node_modules/neo4j-driver-core/lib/error.js:77:16)
at newError (/Users/j/Development/j/Neo4j/server/node_modules/neo4j-driver-core/lib/error.js:113:12)
at NodeChannel._handleConnectionError (/Users/j/Development/j/Neo4j/server/node_modules/neo4j-driver-bolt-connection/lib/channel/node/node-channel.js:227:56)
at Socket.emit (node:events:513:28)
at emitErrorNT (node:internal/streams/destroy:151:8)
at emitErrorCloseNT (node:internal/streams/destroy:116:3)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
constructor: [Function: Neo4jError] { isRetriable: [Function (anonymous)] },
code: 'SessionExpired',
retriable: true
}
}
I am able to query the db from the Neo4j browser without a problem. Can you please help me (a newbie). Thanks in advance.
node server.js and expected the query results to be printed on the console.
When using a Neo4j community edition server, it makes more sense to use the
boltscheme in your driver's connection URI. Theneo4jscheme will attempt to do routing, which is not needed for a standalone server (although it is still supposed to work).So, try replacing
neo4j://localhostwith :bolt://localhost. Even if you still get an error, it should be a different one.Also, in case you are not aware, localhost will not work if your client code is not running on the same machine as the server. If your client is on a different machine, then you need to use the address of the server instead of
localhost.