Help: neo4j-driver example not working

712 views
Skip to first unread message

Mike Frederick

unread,
Jul 19, 2018, 12:16:44 PM7/19/18
to Neo4j
Hello,

I am trying to get a basic JavaScript script in node.js (using version 8.11.3) to neo4j (Community Edition, version 3.3.5) query working using the neo4j-driver (version 1.6.2) package. I found the page on the neo4j website describing this and duplicated the logic in the following script:

const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('http://localhost:7474', neo4j.auth.basic('admin', 'admin'));
const session = driver.session();
const resultPromise = session.run('match (f:Fact) RETURN f');
resultPromise
.then(result => { var r = result; });

When this is executed, at line 5 I get:

(node:2904) UnhandledPromiseRejectionWarning: ReferenceError: Headers is not defined
    at createHttpHeaders (c:\projects\TRI-server\node_modules\neo4j-driver\lib\v1\internal\http\http-request-runner.js:181:17)
    at sendRequest (c:\projects\TRI-server\node_modules\neo4j-driver\lib\v1\internal\http\http-request-runner.js:162:16)
    at HttpRequestRunner.beginTransaction (c:\projects\TRI-server\node_modules\neo4j-driver\lib\v1\internal\http\http-request-runner.js:56:14)
    at HttpSession.run (c:\projects\TRI-server\node_modules\neo4j-driver\lib\v1\internal\http\http-session.js:80:34)
    at repl:1:31
    at ContextifyScript.Script.runInThisContext (vm.js:50:33)
    at REPLServer.defaultEval (repl.js:240:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:468:10)
(node:2904) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:2904) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Does anyone know what is wrong with this? Any help appreciated. 

Benoît Simard

unread,
Jul 20, 2018, 12:14:21 AM7/20/18
to ne...@googlegroups.com
Hi,

The driver is using the bolt protocol, not the http one.
So you just have to replace `http://localhost:7474` by
`bolt://localhost:7687` and it will work !

----
const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('bolt://localhost:7687,
neo4j.auth.basic('admin', 'admin'));
const session = driver.session();
const resultPromise = session.run('match (f:Fact) RETURN f');
resultPromise.then(result => { var r = result; });
----

Cheers
> --
> You received this message because you are subscribed to the Google Groups
> "Neo4j" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to neo4j+un...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Mike Frederick

unread,
Jul 20, 2018, 1:27:33 PM7/20/18
to Neo4j
Thanks. I have replaced the http:// with bolt://

const neo4j = require('neo4j-driver').v1;
const driver = neo4j.driver('bolt://localhost:7474', neo4j.auth.basic('admin', 'admin'));
const session = driver.session();
const resultPromise = session.run('MATCH (f:Fact) RETURN f');
resultPromise
  .then(result => {
    session.close();
  })
  .catch(error => {
    console.log(error);
  });

and now I receive (copy of console when running the script interactively with the node command):

c:\projects\TRI-server>node
> const neo4j = require('neo4j-driver').v1;
undefined
> const driver = neo4j.driver('bolt://localhost:7474', neo4j.auth.basic('admin', 'admin'));
undefined
> const session = driver.session();
undefined
> const resultPromise = session.run('MATCH (f:Fact) RETURN f');
undefined
> resultPromise
Result {
  _stack: '\n    at captureStacktrace (c:\\projects\\TRI-server\\node_modules\\neo4j-driver\\lib\\v1\\result.js:200:15)\n    at new Result (c:\\projects\\TRI-server\\node_modules\\neo4j-driver\\lib\\v1\\result.js:73:19)\n    at Session._run (c:\\projects\\TRI-server\\node_modules\\neo4j-driver\\lib\\v1\\session.js:116:14)\n    at Session.run (c:\\projects\\TRI-server\\node_modules\\neo4j-driver\\lib\\v1\\session.js:95:19)\n    at repl:1:31\n    at ContextifyScript.Script.runInThisContext (vm.js:50:33)\n    at REPLServer.defaultEval (repl.js:240:29)\n    at bound (domain.js:301:14)\n    at REPLServer.runBound [as eval] (domain.js:314:12)\n    at REPLServer.onLine (repl.js:468:10)',
  _streamObserver:
   StreamObserver {
     _fieldKeys: null,
     _fieldLookup: null,
     _queuedRecords: [],
     _tail: null,
     _error: null,
     _hasFailed: false,
     _errorTransformer: [Function],
     _observer: null,
     _conn: null,
     _meta: {} },
  _p: null,
  _statement: 'MATCH (f:Fact) RETURN f',
  _parameters: {},
  _metaSupplier: [Function],
  _connectionHolder:
   ConnectionHolder {
     _mode: 'WRITE',
     _connectionProvider:
      DirectConnectionProvider {
        _hostPort: 'localhost:7474',
        _connectionPool: [Object],
        _driverOnErrorCallback: [Function: bound _driverOnErrorCallback] },
     _referenceCount: 1,
     _connectionPromise: Promise { [Object], domain: [Object] } } }
>   .then(result => {
Invalid REPL keyword
>     session.close();
undefined
>   })
...   .catch(error => {
...     console.log(error);
...   });
c:\projects\TRI-server>

So I still am not able to make a simple query. Anyone able to help?

Benoît Simard

unread,
Jul 20, 2018, 3:08:03 PM7/20/18
to ne...@googlegroups.com
You only have replaced the protocol but not the port !
You also have to replace 7474 by 7687, take a look at my example :)

Cheers.


Mike Frederick

unread,
Jul 20, 2018, 5:41:47 PM7/20/18
to Neo4j
Thank you. This along with a few more changes and I actually have some data coming through.
Reply all
Reply to author
Forward
0 new messages