Neo4j Bolt Connection (Internal)
The `neo4j-driver-bolt-connection` package provides the low-level implementation for establishing and managing connections to Neo4j databases using the binary Bolt Protocol. It is an internal dependency foundational to the official `neo4j-driver` and `neo4j-driver-lite` packages for JavaScript and TypeScript. Crucially, this package is explicitly *not* intended for direct consumption by end-users, serving as an abstraction layer for Bolt protocol specifics. The current stable version is 5.28.3, with version 6.0.x introducing new features like support for Neo4j's Vector type. Release cadence for the main `neo4j-driver` and its internal components, including this one, has evolved; post-6.0, minor releases occur as warranted by significant features or improvements, moving away from a monthly cadence to reduce user update overhead. Key differentiators include its role in abstracting complex network communication and Bolt handshake protocols, enabling the higher-level drivers to offer robust API usability, transaction management, and connection pooling capabilities transparently. While it handles the core communication, developers should always use the comprehensive `neo4j-driver` for a stable and supported experience.
Common errors
-
Error: Cannot find module 'neo4j-driver-bolt-connection'
cause Attempting to import `neo4j-driver-bolt-connection` directly or it's missing as a transitive dependency due to incorrect installation or package manager issues.fixThis package is an internal dependency. Do not install or import it directly. Instead, ensure `neo4j-driver` (or `neo4j-driver-lite`) is correctly installed: `npm install neo4j-driver`. -
TypeError: Cannot read properties of undefined (reading 'protocolVersion')
cause Accessing `ServerInfo.protocolVersion` expecting a `Number` after upgrading to `neo4j-driver` v6.0.0 or higher, but the type has changed to `ProtocolVersion`.fixRefactor code to handle the new `ProtocolVersion` type for `ServerInfo.protocolVersion` in `neo4j-driver` v6.0.0+. Consult the `neo4j-driver` v6 documentation for updated API details on `ServerInfo`.
Warnings
- gotcha This package (`neo4j-driver-bolt-connection`) is an internal component of the official `neo4j-driver` and `neo4j-driver-lite`. It is explicitly *not* intended for direct consumption by end-users. Direct usage can lead to unexpected behavior, API instability, and lack of support.
- breaking The `protocolVersion` property on the `ServerInfo` object changed its type from a `Number` to a new `ProtocolVersion` type in v6.0.0 of the `neo4j-driver`. Code expecting a plain number for Bolt protocol version information will break.
- gotcha TypeScript exports for `Vector` and `vectors` types were initially incorrect or incomplete in the `neo4j-driver` v6.0.0 release, affecting applications utilizing the new Bolt 6.0 features for vector data types.
- gotcha When connecting directly to IP addresses using previous versions of the `neo4j-driver`, users might encounter SNI (Server Name Indication) deprecation messages, indicating a potential issue with hostname verification.
Install
-
npm install neo4j-driver-bolt-connection -
yarn add neo4j-driver-bolt-connection -
pnpm add neo4j-driver-bolt-connection
Imports
- Connection
import { Connection } from 'neo4j-driver-bolt-connection';// This package is for internal use. Use 'neo4j-driver' instead.
- ConnectionProvider
const { ConnectionProvider } = require('neo4j-driver-bolt-connection');// This package is for internal use. Use 'neo4j-driver' instead.
- any internal export
import * as boltInternals from 'neo4j-driver-bolt-connection';
// Refer to the 'neo4j-driver' documentation for public APIs.
Quickstart
import neo4j from 'neo4j-driver';
// IMPORTANT: neo4j-driver-bolt-connection is an internal package.
// Always use the official 'neo4j-driver' for your applications.
const uri = process.env.NEO4J_URI ?? 'bolt://localhost:7687';
const user = process.env.NEO4J_USERNAME ?? 'neo4j';
const password = process.env.NEO4J_PASSWORD ?? 'password';
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
async function queryNeo4j() {
const session = driver.session();
try {
const result = await session.run(
'CREATE (a:Greeting {message: $message}) RETURN a.message AS message',
{ message: 'Hello, Neo4j!' }
);
const singleRecord = result.records[0];
const message = singleRecord.get('message');
console.log(`Successfully created a node with message: ${message}`);
} catch (error) {
console.error('Error connecting to Neo4j or running query:', error);
} finally {
await session.close();
console.log('Session closed.');
}
}
queryNeo4j()
.then(() => driver.close())
.catch(error => {
console.error('Driver encountered an error:', error);
driver.close();
});