What's new

Neo4j - Neo4jError: Connection was closed by server


Active member
Staff member
I've created a google cloud VM instance with neo4j on it, by following this instructions: https://neo4j.com/docs/operations-manual/current/cloud-deployments/neo4j-gcp/single-instance-vm/

The browser Db looks fine: I can view and manipulate from the browser.

The problem is when trying connecting neo4j from nodejs using neo4j-driver npm.

I keep getting this error:

UnhandledPromiseRejectionWarning: Neo4jError: Connection was closed by server
this is the code:

const neo4j = require('neo4j-driver')
const uri = 'bolt://[EXTERNAL_IP]:[PORT]'
const user = 'USER_NAME'
const password = 'PASSWORD'

const createPerson = async () => {
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password), { encrypted : "ENCRYPTION_OFF"})
const session = driver.session()
const personName = 'Bob'
try {
const result = await session.run(
'CREATE (a:person {name: $name}) RETURN a',
{ name: personName }

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

} finally {
await session.close()

// on application exit:
await driver.close()


The code is taken from this link: https://neo4j.com/developer/javascript/

I run this command: gcloud compute ssh my-neo4j-instance in GCP shell, in hope that maybe adding ssh would solve the issue but it didn't.

changing the driver encrypted options to false also didn't help.

Console logging the error print this:

Neo4jError: Connection was closed by server

at captureStacktrace (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:263:15)
at new Result (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\result.js:68:19)
at Session._run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:174:14)
at Session.run (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\node_modules\neo4j-driver\lib\session.js:135:19)
at createPerson (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:12:38)
at Object.<anonymous> (C:\Users\user\Desktop\Home Work\MyProject\LotteryService\src\index.js:31:1)
at Module._compile (internal/modules/cjs/loader.js:959:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14) {

code: 'ServiceUnavailable',
name: 'Neo4jError'

what am i missing ?


I looked the google cloud logs. all i saw was logs for the start and stop of the vm.

Also, i fixed the code for the async function call in the main file. so instead of the


i tried this:

(async() => {
console.log('before start');

await createPerson();

console.log('after start');

still no good, still: Neo4jError: Connection was closed by server. I also asked in neo4j blogs but got no answers.


I saw my issue in a different stack-overflow post. The answer there was to finish the logging to neo4j, by changing the password. but I already did that... Also I joined the neo4j slack group but didn't got an answer still.

Continue reading...