JavaScript driver

This section presents the breaking changes between the Neo4j 1.7 JavaScript driver and 4.x JavaScript driver.

The latest version of the JavaScript driver for Neo4j can be found on the JavaScript driver’s official page.

  • session#close() and driver#close() now return Promises, and no longer accept callback function arguments.

  • driver.onError and driver.onCompleted callbacks have been removed. Errors should be monitored on related code paths (e.g. through Promise#catch, etc.).

Example 1. Example of changes between the 1.7 JavaScript driver and the 4.0 JavaScript driver
Example code for the 4.0 JavaScript driver Example code for the 1.7 JavaScript driver
var neo4j = require('neo4j-driver')
...
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password))
...

const session = driver.session()
try {
  const tx = session.beginTransaction()
  const result = await tx.run('CREATE (a:Greeting) SET a.message = $message RETURN a.message + ", from node " + id(a)', { message: 'hello, world' })
  const greeting = result.records[0].get(0)
  console.log(greeting)
  await tx.commit()
} finally {
  await session.close()
}
var neo4j = require('neo4j-driver').v1
...
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password))
...

const session = driver.session()
try {
  const tx = session.beginTransaction()
  const result = await tx.run('CREATE (a:Greeting) SET a.message = $message RETURN a.message + ", from node " + id(a)', { message: 'hello, world' })
  const greeting = result.records[0].get(0)
  console.log(greeting)
  await tx.commit()
} finally {
  session.close(callback) // another session can be chained in callback
}