Neo4j-driver example for javascript is not working when database is not localhost

neo4j-driver

(Aqureshi) #1

Hi,

this is what my index.js looks like:

const neo4j = require('neo4j-driver').v1;


const driver = neo4j.driver("https://bolt.custom-endpoint.ca:443", neo4j.auth.basic("neo4j", "password123"));

/* https://bolt.custom-endpoint.ca:443 connects to the 0.0.0.0:7687 port inside 
the docker container in which the neo4j db is running. The neo4j.conf has been changed
 to accommodate non-local requests
*/
const session = driver.session();

const personName = 'Alice';
const resultPromise = session.run(
  'CREATE (a:Person {name: $name}) RETURN a',
  {name: personName}
);

resultPromise.then(result => {
  session.close();

  const singleRecord = result.records[0];
  const node = singleRecord.get(0);

  console.log(node.properties.name);

  // on application exit:
  driver.close();
});

when I run that I get the following error:

(node:561) UnhandledPromiseRejectionWarning: ReferenceError: Headers is not defined
    at createHttpHeaders (/mnt/c/Users/name/Desktop/relationship-mapper/node_modules/neo4j-driver/lib/v1/internal/http/http-request-runner.js:181:17)
    at sendRequest (/mnt/c/Users/name/Desktop/relationship-mapper/node_modules/neo4j-driver/lib/v1/internal/http/http-request-runner.js:162:16)
    at HttpRequestRunner.beginTransaction (/mnt/c/Users/name/Desktop/relationship-mapper/node_modules/neo4j-driver/lib/v1/internal/http/http-request-runner.js:56:14)
    at HttpSession.run (/mnt/c/Users/name/Desktop/relationship-mapper/node_modules/neo4j-driver/lib/v1/internal/http/http-session.js:80:34)
    at Object.<anonymous> (/mnt/c/Users/name/Desktop/relationship-mapper/index.js:7:31)
    at Module._compile (module.js:653:30)
    at Object.Module._extensions..js (module.js:664:10)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
(node:561) 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:561) [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.

I know my bolt endpoint is working fine because when i connect to the neo4j browser console and make it use the bolt connection through the settings, everything works fine. image

I can login and make cypher queries successfully over the bolt connection through the browser console.

However the neo4j-driver example code doesn't seem to work. I am running the neo4j docker container on a server, hence the different url. The example works fine when I run the docker container locally (and change the url to bolt://localhost:7687).

Any ideas of what's going wrong? thanks!


(Benoit Simard) #2

Hi,

You are using an HTTP url to initiate your driver ( https://bolt.custom-endpoint.ca:443) but your docker container is configure to use the port 443 as the bolt one.

Can you try it to change it like that :

const driver = neo4j.driver("bolt://bolt.custom-endpoint.ca:443", neo4j.auth.basic("neo4j", "password123"));

(Aqureshi) #3

Edit: Nevermind! I got it fixed. Thank you so much

Thanks! However, now i'm getting the following error:

(node:3831) UnhandledPromiseRejectionWarning: Neo4jError: 139852753513344:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:827:

which is weird because the neo4j browser doesn't get this error when using bolt.

Any ideas?