Neo4j JS Driver slow response

Hi All,
when I am running the below query in neo4j browser, it takes around 2-3ms to give results but when I run using JS driver, it takes around 450-500ms to run. the HTTP endpoint takes 200ms to run.
I am using the latest driver (ran this cmd npm install neo4j-driver ) .
below is the query

match(u:User{id:'5b186ae490d3be0b45dfe4c4'})-[:POSTED_ON_2020_05_17|POSTED_ON_2020_05_10]->(p:Post) return p order by p.createdAt

I am not sure if there is any mistake from my side. Can someone please help me?
below is the JS snippet I used

let [driver, session] = getDriverAndSession();
      var t0 =;
      var dayArr = ["2020_05_17", "2020_05_10"],
        userID = "5b186ae490d3bf0b45dfe4c4",
        fnlRes = [],
        querySkltn = `match(u:User{id:"${userID}"})-[:{fnldate}]->(p:Post) return p order by p.createdAt;`,
        relSkltn = `POSTED_ON_{date}|`,
        tempRel = "";
      const runQuery = (query) => {
        return new Promise((resolve, reject) => {
            .then((res) => {
              // console.log(`running for ${date}`);
              // var temp = [];
              // for (let index = 0; index < res.records.length; index++) {
              //   temp.push(res.records[index].get("p").properties);
              //   if (index == res.records.length - 1) {
              //     resolve(temp);
              //   }
              // }
            .catch((e) => {
      for (let index = 0; index < dayArr.length; index++) {
        tempRel = tempRel.concat(relSkltn.replace("{date}", dayArr[index]));
      tempRel = tempRel.slice(0, -1);
      querySkltn = querySkltn.replace("{fnldate}", tempRel);
      var res = await runQuery(querySkltn);
      var t1 =;
      console.log("Call took " + (t1 - t0) + " milliseconds.");

Hi Sai,

As I said in the neode issue, the driver you are using is exactly the same as the one used in Neo4j Browser so the issue won't be the driver itself.

A couple of things to check:

  • Are you querying with the same user id and getting the exact same results? If the user you are querying here has many POSTED_ON_* relationships then the query will take longer.
  • Do you have an index on constraint on the id property for User? If not, and you have added more users since the original query this will be slower
  • Closing the session and driver may also take time, but this won't be accounted for in the time calculated in the time

It is also a good idea to get into the practise of using $parameters - this will speed up subsequent queries because neo4j won't have to profile the query before it runs. You also protect yourself against the user injecting malicious commands into the query.

You also don't need the runQuery function because already returns a promise. You could optimise the code into something like the following:

const dayArr = ["2020_05_17", "2020_05_10"]

const query = `
    MATCH (n:User {id: $id})-[:${ => `POSTED_ON_${date}`).join('|') }]->(p:Post) 
    RETURN p 
    ORDER BY p.createdAt
const params = { id:  '5b186ae490d3bf0b45dfe4c4' }, params)
    .then(res => => row.get('p')))
    .then(arrayOfPostNodes => {
        // Do something with the array of post nodes

The result of the query also comes with a summary that you can double check the performance on:

const consumedAfter = res.summary.resultConsumedAfter.toNumber()
const availableAfter = res.summary.resultAvailableAfter.toNumber()

return `
    Started streaming ${res.records.length} record${res.records.length === 1 ? '' : 's'} 
    after ${availableAfter}ms 
    and completed after ${consumedAfter}ms

I do have indexes on it but I found the issue. The issue wasn't with the driver. I have my neo4j enterprise on GCP and I am trying on my local machine to connect to that instance and run the query. When I deployed the same JS script onto one of the VM, I could see the results are coming in 30ms. the time dropped from 400ms to 30ms. I am thinking this 30ms is due to opening and closing of session object and all but the 400ms might be because of network latency. I am not too sure whether 30ms is a good sign but as of now for me 400 to 30ms is a huge thing.

Also, I will remember this parameter usage.Thanks for the reply Adam