Using neo4j-driver with nest js


I have a code using nest js to acces the database through the bolt protocol. The tutorial I followed ( installed the driver version 1.7.6, when I install that, i get the error: [ExceptionsHandler] Client network socket disconnected before secure TLS connection was established. If I update the driver, an error related with v1 shows up, and I don't know exactly what to do to change the v1 into the newer version of the driver in the code. Thank you!

Code: import { Injectable, Inject } from '@ nestjs/common';
//import { v1 } from 'neo4j-driver';
var neo4j = require('neo4j-driver');
@ Injectable()
export class Neo4jService {
constructor(@ Inject('Neo4j') private readonly neo4j: v1.Driver) {}
async findAll(): Promise {
return this.neo4j.session().run('MATCH (n) RETURN n');

Hey @ziadtaleb97,

Sorry it's a bit late but I've been experimenting with NestJS and Neo4j for the past few days and I've put together a module that you can use to get an instance of the Driver in your services. You register Neo4jModule as a dynamic module with your database connection details, then you can inject the Neo4jService into your modules

import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { Neo4jModule } from 'nest-neo4j'

  imports: [
      scheme: 'neo4j',
      host: 'localhost',
      port: 7687,
      username: 'neo4j',
      password: 'neo'
  controllers: [AppController],
  providers: [AppService],
export class AppModule {}

Then to inject:

import { Neo4jService } from 'nest-neo4j'

export class AppController {
  constructor(private readonly neo4jService: Neo4jService){}
  // ...

Right now it's got methods for:

  • Reading read(cypher: string, params: object)
  • Writing write(cypher: string, params: object)
  • Getting a read/write session - getReadSession(database?: string) or getWriteSession(database?: string)

Let me know if it's useful. I'm also looking into how we can integrate with packages like TypeORM so if you use anything like that or have any preference then let me know.