cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Connecting neo4j to node

I am trying to connect nodejs to the neo4j desktop, in which I created a database named as voters, a user is a default only which is named neo4j, I have not added any user.
But I don't think I am writing the correct code in my node to connect to neo4j, so someone can help and check if it is correct. I have already installed all the neo4j-drivers in the node

const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic(neo4j,neo4j));

const session = driver.session();

As when I am running the queries it is giving me the following errors, and I think there is some connection problem.

{ Neo4jError: Unable to pack the given value: function driver(url, authToken) {
  var config = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  (0, _util.assertString)(url, 'Bolt URL');

  var parsedUrl = _urlUtil["default"].parseDatabaseUrl(url);

  if (['bolt+routing', 'neo4j'].indexOf(parsedUrl.scheme) !== -1) {
    return new _routingDriver["default"](_serverAddress["default"].fromUrl(parsedUrl.hostAndPort), parsedUrl.query, USER_AGENT, authToken, config);
  } else if (parsedUrl.scheme === 'bolt') {
    if (!(0, _util.isEmptyObjectOrNull)(parsedUrl.query)) {
      throw new Error("Parameters are not supported with scheme 'bolt'. Given URL: '".concat(url, "'"));
    }

    return new _driver.Driver(_serverAddress["default"].fromUrl(parsedUrl.hostAndPort), USER_AGENT, authToken, config);
  } else if (parsedUrl.scheme === 'http' || parsedUrl.scheme === 'https') {
    return new _httpDriver["default"](parsedUrl, USER_AGENT, authToken, config);
  } else {
    throw new Error("Unknown scheme: ".concat(parsedUrl.scheme));
  }
}

    at captureStacktrace (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\result.js:199:15)
    at new Result (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\result.js:65:19)
    at Session._run (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\session.js:152:14)
    at Session.run (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\neo4j-driver\lib\v1\session.js:130:19)
    at router.post (C:\Users\NISHU\Angular\voters - Copy\backend\services.js:51:17)
    at Layer.handle [as handle_request] (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\express\lib\router\route.js:137:13)
    at Immediate._onImmediate (C:\Users\NISHU\Angular\voters - Copy\backend\node_modules\multer\lib\make-middleware.js:53:37)
    at runCallback (timers.js:706:11)
    at tryOnImmediate (timers.js:676:5) code: 'ProtocolError', name: 'Neo4jError' }
3 REPLIES 3

jsmccrumb
Graph Buddy

Hello,

Right now, the code would treat the login as the variable neo4j, you need to have it as a string. Try:

const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('neo4j', 'neo4j'));

(notice addition of single quotes around login info)

Quick follow up.
First, thanks for this. How do we add a database name to the driver? We can do this in python and R drivers but I don't see documentation how to add database to the driver constructor in the basic function.

var session = driver.session({ database:'db_name', defaultAccessMode: neo4j.session.READ })