{"id":13529151,"url":"https://github.com/neo4j/neo4j-javascript-driver","last_synced_at":"2025-05-13T19:14:37.884Z","repository":{"id":35311544,"uuid":"39573021","full_name":"neo4j/neo4j-javascript-driver","owner":"neo4j","description":"Neo4j Bolt driver for JavaScript","archived":false,"fork":false,"pushed_at":"2025-05-07T14:42:11.000Z","size":33128,"stargazers_count":874,"open_issues_count":31,"forks_count":150,"subscribers_count":77,"default_branch":"5.0","last_synced_at":"2025-05-07T15:46:05.438Z","etag":null,"topics":["bolt","database","driver","javascript","neo4j","neo4j-driver"],"latest_commit_sha":null,"homepage":"https://neo4j.com/docs/javascript-manual/current/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/neo4j.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-07-23T14:46:34.000Z","updated_at":"2025-04-19T12:30:51.000Z","dependencies_parsed_at":"2024-11-07T09:26:17.370Z","dependency_job_id":"38695dd4-84ab-4cb2-8003-7e8f73bbd616","html_url":"https://github.com/neo4j/neo4j-javascript-driver","commit_stats":{"total_commits":1368,"total_committers":68,"mean_commits":20.11764705882353,"dds":0.7536549707602339,"last_synced_commit":"432463798fc1c56f0d9b84a3d7de3ede8a28f5fa"},"previous_names":[],"tags_count":157,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fneo4j-javascript-driver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fneo4j-javascript-driver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fneo4j-javascript-driver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neo4j%2Fneo4j-javascript-driver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neo4j","download_url":"https://codeload.github.com/neo4j/neo4j-javascript-driver/tar.gz/refs/heads/5.0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252912189,"owners_count":21824059,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bolt","database","driver","javascript","neo4j","neo4j-driver"],"created_at":"2024-08-01T07:00:33.771Z","updated_at":"2025-05-13T19:14:37.866Z","avatar_url":"https://github.com/neo4j.png","language":"JavaScript","funding_links":[],"categories":["Connectors","JavaScript","Bolt"],"sub_categories":["Bolt"],"readme":"# Neo4j Driver for JavaScript\n\nThis is the official Neo4j driver for JavaScript.\n\nStarting with 5.0, the Neo4j Drivers will be moving to a monthly release cadence. A minor version will be released on the last Friday of each month so as to maintain versioning consistency with the core product (Neo4j DBMS) which has also moved to a monthly cadence.\n\nAs a policy, patch versions will not be released except on rare occasions. Bug fixes and updates will go into the latest minor version and users should upgrade to that. Driver upgrades within a major version will never contain breaking API changes.\n\nSee also: https://neo4j.com/developer/kb/neo4j-supported-versions/\n\nResources to get you started:\n\n- [API Documentation](https://neo4j.com/docs/api/javascript-driver/current/)\n- [Neo4j Manual](https://neo4j.com/docs/)\n- [Neo4j Refcard](https://neo4j.com/docs/cypher-refcard/current/)\n\n## What's New in 5.x\n\n- [Changelog](https://github.com/neo4j/neo4j-javascript-driver/wiki/5.0-changelog)\n\n## Including the Driver\n\n### In Node.js application\n\nStable channel:\n\n```shell\nnpm install neo4j-driver\n```\n\nPre-release channel:\n\n```shell\nnpm install neo4j-driver@next\n```\n\nPlease note that `@next` only points to pre-releases that are not suitable for production use.\nTo get the latest stable release omit `@next` part altogether or use `@latest` instead.\n\n```javascript\nvar neo4j = require('neo4j-driver')\n```\n\nDriver instance should be closed when Node.js application exits:\n\n```javascript\ndriver.close() // returns a Promise\n```\n\notherwise application shutdown might hang or it might exit with a non-zero exit code.\n\n### In web browser\n\nWe build a special browser version of the driver, which supports connecting to Neo4j over WebSockets.\nIt can be included in an HTML page using one of the following tags:\n\n```html\n\u003c!-- Direct reference --\u003e\n\u003cscript src=\"lib/browser/neo4j-web.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- unpkg CDN non-minified --\u003e\n\u003cscript src=\"https://unpkg.com/neo4j-driver\"\u003e\u003c/script\u003e\n\u003c!-- unpkg CDN minified for production use, version X.Y.Z --\u003e\n\u003cscript src=\"https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.min.js\"\u003e\u003c/script\u003e\n\n\u003c!-- jsDelivr CDN non-minified --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/neo4j-driver\"\u003e\u003c/script\u003e\n\u003c!-- jsDelivr CDN minified for production use, version X.Y.Z --\u003e\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.min.js\"\u003e\u003c/script\u003e\n```\n\nThis will make a global `neo4j` object available, where you can create a driver instance with `neo4j.driver`:\n\n```javascript\nvar driver = neo4j.driver(\n  'neo4j://localhost',\n  neo4j.auth.basic('neo4j', 'password')\n)\n```\n\nFrom `5.4.0`, this version is also exported as ECMA Script Module.\nIt can be imported from a module using the following statements:\n\n```javascript\n// Direct reference\nimport neo4j from 'lib/browser/neo4j-web.esm.min.js'\n\n// unpkg CDN non-minified , version X.Y.Z where X.Y.Z \u003e= 5.4.0\nimport neo4j from 'https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.js'\n\n// unpkg CDN minified for production use, version X.Y.Z where X.Y.Z \u003e= 5.4.0\nimport neo4j from 'https://unpkg.com/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.min.js'\n\n// jsDelivr CDN non-minified, version X.Y.Z where X.Y.Z \u003e= 5.4.0\nimport neo4j from 'https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.js'\n\n// jsDelivr CDN minified for production use, version X.Y.Z where X.Y.Z \u003e= 5.4.0\nimport neo4j from 'https://cdn.jsdelivr.net/npm/neo4j-driver@X.Y.Z/lib/browser/neo4j-web.esm.min.js'\n\n```\n\nIt is not required to explicitly close the driver on a web page. Web browser should gracefully close all open\nWebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime\nis not the same as the lifetime of the web page:\n\n```javascript\ndriver.close() // returns a Promise\n```\n\n## Usage examples\n\n### Constructing a Driver\n\n```javascript\n// Create a driver instance, for the user `neo4j` with password `password`.\n// It should be enough to have a single driver per database per application.\nvar driver = neo4j.driver(\n  'neo4j://localhost',\n  neo4j.auth.basic('neo4j', 'password')\n)\n\n// Close the driver when application exits.\n// This closes all used network connections.\nawait driver.close()\n```\n\n### Acquiring a Session\n\n#### Regular Session\n\n```javascript\n// Create a session to run Cypher statements in.\n// Note: Always make sure to close sessions when you are done using them!\nvar session = driver.session()\n```\n\n##### with a Default Access Mode of `READ`\n\n```javascript\nvar session = driver.session({ defaultAccessMode: neo4j.session.READ })\n```\n\n##### with Bookmarks\n\n```javascript\nvar session = driver.session({\n  bookmarks: [bookmark1FromPreviousSession, bookmark2FromPreviousSession]\n})\n```\n\n##### against a Database\n\n```javascript\nvar session = driver.session({\n  database: 'foo',\n  defaultAccessMode: neo4j.session.WRITE\n})\n```\n\n#### Reactive Session\n\n```javascript\n// Create a reactive session to run Cypher statements in.\n// Note: Always make sure to close sessions when you are done using them!\nvar rxSession = driver.rxSession()\n```\n\n##### with a Default Access Mode of `READ`\n\n```javascript\nvar rxSession = driver.rxSession({ defaultAccessMode: neo4j.session.READ })\n```\n\n##### with Bookmarks\n\n```javascript\nvar rxSession = driver.rxSession({\n  bookmarks: [bookmark1FromPreviousSession, bookmark2FromPreviousSession]\n})\n```\n\n##### against a Database\n\n```javascript\nvar rxSession = driver.rxSession({\n  database: 'foo',\n  defaultAccessMode: neo4j.session.WRITE\n})\n```\n\n### Transaction functions\n\n```javascript\n// Transaction functions provide a convenient API with minimal boilerplate and\n// retries on network fluctuations and transient errors. Maximum retry time is\n// configured on the driver level and is 30 seconds by default:\n// Applies both to standard and reactive sessions.\nneo4j.driver('neo4j://localhost', neo4j.auth.basic('neo4j', 'password'), {\n  maxTransactionRetryTime: 30000\n})\n```\n\n#### Reading with Async Session\n\n```javascript\n// It is possible to execute read transactions that will benefit from automatic\n// retries on both single instance ('bolt' URI scheme) and Causal Cluster\n// ('neo4j' URI scheme) and will get automatic load balancing in cluster deployments\nvar readTxResultPromise = session.executeRead(txc =\u003e {\n  // used transaction will be committed automatically, no need for explicit commit/rollback\n\n  var result = txc.run('MATCH (person:Person) RETURN person.name AS name')\n  // at this point it is possible to either return the result or process it and return the\n  // result of processing it is also possible to run more statements in the same transaction\n  return result\n})\n\n// returned Promise can be later consumed like this:\nreadTxResultPromise\n  .then(result =\u003e {\n    console.log(result.records)\n  })\n  .catch(error =\u003e {\n    console.log(error)\n  })\n  .then(() =\u003e session.close())\n```\n\n#### Reading with Reactive Session\n\n```javascript\nrxSession\n  .executeRead(txc =\u003e\n    txc\n      .run('MATCH (person:Person) RETURN person.name AS name')\n      .records()\n      .pipe(map(record =\u003e record.get('name')))\n  )\n  .subscribe({\n    next: data =\u003e console.log(data),\n    complete: () =\u003e console.log('completed'),\n    error: err =\u003e console.log(error)\n  })\n```\n\n#### Writing with Async Session\n\n```javascript\n// It is possible to execute write transactions that will benefit from automatic retries\n// on both single instance ('bolt' URI scheme) and Causal Cluster ('neo4j' URI scheme)\nvar writeTxResultPromise = session.executeWrite(async txc =\u003e {\n  // used transaction will be committed automatically, no need for explicit commit/rollback\n\n  var result = await txc.run(\n    \"MERGE (alice:Person {name : 'Alice'}) RETURN alice.name AS name\"\n  )\n  // at this point it is possible to either return the result or process it and return the\n  // result of processing it is also possible to run more statements in the same transaction\n  return result.records.map(record =\u003e record.get('name'))\n})\n\n// returned Promise can be later consumed like this:\nwriteTxResultPromise\n  .then(namesArray =\u003e {\n    console.log(namesArray)\n  })\n  .catch(error =\u003e {\n    console.log(error)\n  })\n  .then(() =\u003e session.close())\n```\n\n#### Writing with Reactive Session\n\n```javascript\nrxSession\n  .executeWrite(txc =\u003e\n    txc\n      .run(\"MERGE (alice:Person {name: 'James'}) RETURN alice.name AS name\")\n      .records()\n      .pipe(map(record =\u003e record.get('name')))\n  )\n  .subscribe({\n    next: data =\u003e console.log(data),\n    complete: () =\u003e console.log('completed'),\n    error: error =\u003e console.log(error)\n  })\n```\n\n### Consuming Records\n\n#### Consuming Records with Streaming API\n\n```javascript\n// Run a Cypher statement, reading the result in a streaming manner as records arrive:\nsession\n  .run('MERGE (alice:Person {name : $nameParam}) RETURN alice.name AS name', {\n    nameParam: 'Alice'\n  })\n  .subscribe({\n    onKeys: keys =\u003e {\n      console.log(keys)\n    },\n    onNext: record =\u003e {\n      console.log(record.get('name'))\n    },\n    onCompleted: () =\u003e {\n      session.close() // returns a Promise\n    },\n    onError: error =\u003e {\n      console.log(error)\n    }\n  })\n```\n\nSubscriber API allows following combinations of `onKeys`, `onNext`, `onCompleted` and `onError` callback invocations:\n\n- zero or one `onKeys`,\n- zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked in this case\n- zero or more `onNext` followed by `onError` when operation failed. Callback `onError` might be invoked after couple `onNext` invocations because records are streamed lazily by the database. `onCompleted` will not be invoked in this case.\n\n#### Consuming Records with Promise API\n\n```javascript\n// the Promise way, where the complete result is collected before we act on it:\nsession\n  .run('MERGE (james:Person {name : $nameParam}) RETURN james.name AS name', {\n    nameParam: 'James'\n  })\n  .then(result =\u003e {\n    result.records.forEach(record =\u003e {\n      console.log(record.get('name'))\n    })\n  })\n  .catch(error =\u003e {\n    console.log(error)\n  })\n  .then(() =\u003e session.close())\n```\n\n#### Consuming Records with Reactive API\n\n```javascript\nrxSession\n  .run('MERGE (james:Person {name: $nameParam}) RETURN james.name AS name', {\n    nameParam: 'Bob'\n  })\n  .records()\n  .pipe(\n    map(record =\u003e record.get('name')),\n    concatWith(rxSession.close())\n  )\n  .subscribe({\n    next: data =\u003e console.log(data),\n    complete: () =\u003e console.log('completed'),\n    error: err =\u003e console.log(err)\n  })\n```\n\n### Explicit Transactions\n\n#### With Async Session\n\n```javascript\n// run statement in a transaction\nconst txc = session.beginTransaction()\ntry {\n  const result1 = await txc.run(\n    'MERGE (bob:Person {name: $nameParam}) RETURN bob.name AS name',\n    {\n      nameParam: 'Bob'\n    }\n  )\n  result1.records.forEach(r =\u003e console.log(r.get('name')))\n  console.log('First query completed')\n\n  const result2 = await txc.run(\n    'MERGE (adam:Person {name: $nameParam}) RETURN adam.name AS name',\n    {\n      nameParam: 'Adam'\n    }\n  )\n  result2.records.forEach(r =\u003e console.log(r.get('name')))\n  console.log('Second query completed')\n\n  await txc.commit()\n  console.log('committed')\n} catch (error) {\n  console.log(error)\n  await txc.rollback()\n  console.log('rolled back')\n} finally {\n  await session.close()\n}\n```\n\n#### With Reactive Session\n\n```javascript\nrxSession\n  .beginTransaction()\n  .pipe(\n    mergeMap(txc =\u003e\n      concatWith(\n        txc\n          .run(\n            'MERGE (bob:Person {name: $nameParam}) RETURN bob.name AS name',\n            {\n              nameParam: 'Bob'\n            }\n          )\n          .records()\n          .pipe(map(r =\u003e r.get('name'))),\n        of('First query completed'),\n        txc\n          .run(\n            'MERGE (adam:Person {name: $nameParam}) RETURN adam.name AS name',\n            {\n              nameParam: 'Adam'\n            }\n          )\n          .records()\n          .pipe(map(r =\u003e r.get('name'))),\n        of('Second query completed'),\n        txc.commit(),\n        of('committed')\n      ).pipe(catchError(err =\u003e txc.rollback().pipe(throwError(() =\u003e err))))\n    )\n  )\n  .subscribe({\n    next: data =\u003e console.log(data),\n    complete: () =\u003e console.log('completed'),\n    error: error =\u003e console.log(error)\n  })\n```\n\n### Numbers and the Integer type\n\nThe Neo4j type system uses 64-bit signed integer values. The range of values is between `-(2`\u003csup\u003e`64`\u003c/sup\u003e`- 1)` and `(2`\u003csup\u003e`63`\u003c/sup\u003e`- 1)`.\n\nHowever, JavaScript can only safely represent integers between `Number.MIN_SAFE_INTEGER` `-(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)`.\n\nIn order to support the full Neo4j type system, the driver will not automatically convert to javascript integers.\nAny time the driver receives an integer value from Neo4j, it will be represented with an internal integer type by the driver.\n\n_**Any javascript number value passed as a parameter will be recognized as `Float` type.**_\n\n#### Writing integers\n\nNumbers written directly e.g. `session.run(\"CREATE (n:Node {age: $age})\", {age: 22})` will be of type `Float` in Neo4j.\n\nTo write the `age` as an integer the `neo4j.int` method should be used:\n\n```javascript\nvar neo4j = require('neo4j-driver')\n\nsession.run('CREATE (n {age: $myIntParam})', { myIntParam: neo4j.int(22) })\n```\n\nTo write an integer value that are not within the range of `Number.MIN_SAFE_INTEGER` `-(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)`, use a string argument to `neo4j.int`:\n\n```javascript\nsession.run('CREATE (n {age: $myIntParam})', {\n  myIntParam: neo4j.int('9223372036854775807')\n})\n```\n\n#### Reading integers\n\nIn Neo4j, the type Integer can be larger what can be represented safely as an integer with JavaScript Number.\n\nIt is only safe to convert to a JavaScript Number if you know that the number will be in the range `Number.MIN_SAFE_INTEGER` `-(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)` and `Number.MAX_SAFE_INTEGER` `(2`\u003csup\u003e`53`\u003c/sup\u003e`- 1)`.\n\nIn order to facilitate working with integers the driver include `neo4j.isInt`, `neo4j.integer.inSafeRange`, `neo4j.integer.toNumber`, and `neo4j.integer.toString`.\n\n```javascript\nvar smallInteger = neo4j.int(123)\nif (neo4j.integer.inSafeRange(smallInteger)) {\n  var aNumber = smallInteger.toNumber()\n}\n```\n\nIf you will be handling integers that is not within the JavaScript safe range of integers, you should convert the value to a string:\n\n```javascript\nvar largeInteger = neo4j.int('9223372036854775807')\nif (!neo4j.integer.inSafeRange(largeInteger)) {\n  var integerAsString = largeInteger.toString()\n}\n```\n\n#### Enabling native numbers\n\nStarting from 1.6 version of the driver it is possible to configure it to only return native numbers instead of custom `Integer` objects.\nThe configuration option affects all integers returned by the driver. **Enabling this option can result in a loss of precision and incorrect numeric\nvalues being returned if the database contains integer numbers outside of the range** `[Number.MIN_SAFE_INTEGER, Number.MAX_SAFE_INTEGER]`.\nTo enable potentially lossy integer values use the driver's configuration object:\n\n```javascript\nvar driver = neo4j.driver(\n  'neo4j://localhost',\n  neo4j.auth.basic('neo4j', 'password'),\n  { disableLosslessIntegers: true }\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneo4j%2Fneo4j-javascript-driver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneo4j%2Fneo4j-javascript-driver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneo4j%2Fneo4j-javascript-driver/lists"}