Sriharsha Guduguntla
Sriharsha Guduguntla

Reputation: 171

How to fix nodejs neo4j driver ECONNREFUSED error?

EDIT:

The error was occurring because I had been using Neo4j version 2.3.5. After updating to version 3.0.4 (latest version), the program works.


I am receiving the following error when performing session.run() with the neo4j driver.

The error I am receiving in the console:

{ [Error: connect ECONNREFUSED 127.0.0.1:7687]
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '127.0.0.1',
port: 7687 }

Here is my app.js file.

var express = require("express");
var path = require("path");
var logger = require("morgan");
var bodyParser = require("body-parser");
var request = require("request");
var neo4j = require("neo4j-driver").v1;

var app = express();

//View Engine
app.set("views", path.join(__dirname, 'views'));
app.set("view engine", "ejs");

app.use(logger("dev"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
  extended: false
}));

app.use(express.static(path.join(__dirname, "public")));

var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();

app.get("/", function(req, res) {
  session
    .run("MATCH (n) RETURN n")
    .then(function(result) {
      console.log(result.records[0]);
      session.close();
      driver.close();
    }).catch(function(err) {
      console.log(err);
    });

  res.send("It Works!");
});

app.listen(3000);

console.log("Server Started on Port 3000");

module.exports = app;

Here is my package.json file:

 {
  "name": "sai-node-neo4j",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "body-parser": "*",
    "ejs": "2.4.2",
    "express": "*",
    "morgan": "*",
    "neo4j-driver":"*"
  }
}

Upvotes: 1

Views: 3363

Answers (1)

Clintm
Clintm

Reputation: 4877

For me I was getting this error when I was using docker and docker-compose and addressing the neo4j instance with localhost. I used the same key I used for neo4j in my docker-compose.yml which was "neo4j" to address it. (i.e. bolt://neo4j)

web:
  image: node:latest
  volumes:
   - .:/usr/src/app
  links:
   - neo4j
  ports:
   - "3000:3000"
  working_dir: /usr/src/app
  entrypoint: npm start
neo4j:
  image: neo4j:latest
  ports:
   - "7473:7473"
   - "7474:7474"
   - "7687:7687"
  volumes:
   - ./db/dbms:/data

Upvotes: 2

Related Questions