How to query Graph data in Redis using JavaScript

Ajeet Raina
Ajeet Raina, Former Developer Growth Manager at Redis

Redis is phasing out RedisGraphThis blog post explains the motivation behind this decision and the implications for existing Redis customers and community members.

End of support is scheduled for January 31, 2025.

RedisGraph is the fastest graph database that processes complex graph operations in real time, 10x – 600x faster than any other graph database. Show how your data is connected through multiple visualization integrations including RedisInsight, Linkurious, and Graphileon. Query graphs using the industry-standard Cypher query language and easily use graph capabilities from application code.

RedisGraph JavaScript Client#

Follow the steps below to get started with RedisGraph with Java:

Step 1. Run Redis Stack Docker container#

 docker run -p 6379:6379 --name redis/redis-stack

Step 2. Verify if RedisGraph module is loaded#

 info modules
 # Modules

Step 3. Clone the repository#

 git clone

Step 4. Install the packages locally#

 npm install redisgraph.js

Step 5. Write a JavaScript code#

const RedisGraph = require('redisgraph.js').Graph;

let graph = new RedisGraph('social');

(async () => {
  await graph.query("CREATE (:person{name:'roi',age:32})");
  await graph.query("CREATE (:person{name:'amit',age:30})");
  await graph.query(
    "MATCH (a:person), (b:person) WHERE ( = 'roi' AND'amit') CREATE (a)-[:knows]->(b)",

  // Match query.
  let res = await graph.query(
    'MATCH (a:person)-[:knows]->(:person) RETURN',
  while (res.hasNext()) {
    let record =;

  // Match with parameters.
  let param = { age: 30 };
  res = await graph.query('MATCH (a {age: $age}) return', param);
  while (res.hasNext()) {
    let record =;

  // Named paths matching.
  res = await graph.query('MATCH p = (a:person)-[:knows]->(:person) RETURN p');
  while (res.hasNext()) {
    let record =;
    // See path.js for more path API.

Save the above file as "app.js".

Step 6. Execute the Script#

 node app.js

Step 7. Monitor the Graph query#

 1632898652.415702 [0] "info"
 1632898652.418225 [0] "graph.query" "social" "CREATE (:person{name:'roi',age:32})" "--compact"
 1632898652.420399 [0] "graph.query" "social" "CREATE (:person{name:'amit',age:30})" "--compact"
 1632898652.421857 [0] "graph.query" "social" "MATCH (a:person), (b:person) WHERE ( = 'roi' AND'amit') CREATE (a)-[:knows]->(b)" "--compact"
 1632898652.424911 [0] "graph.query" "social" "MATCH (a:person)-[:knows]->(:person) RETURN" "--compact"
 1632898652.429658 [0] "graph.query" "social" "CYPHER age=30  MATCH (a {age: $age}) return" "--compact"
 1632898652.431221 [0] "graph.query" "social" "MATCH p = (a:person)-[:knows]->(:person) RETURN p" "--compact"
 1632898652.433146 [0] "graph.query" "social" "CALL db.labels()" "--compact"
 1632898652.434781 [0] "graph.query" "social" "CALL db.propertyKeys()" "--compact"
 1632898652.436574 [0] "graph.query" "social" "CALL db.relationshipTypes()" "--compact"
 1632898652.438559 [0] "graph.delete" "social"

Step 8. Install RedisInsight#

Run the RedisInsight container. The easiest way is to run the following command:

 docker run -d -v redisinsight:/db -p 8001:8001 redislabs/redisinsight:latest

Step 9. Accessing RedisInsight#

Next, point your browser to http://localhost:8001.

Step 10. Run the Graph Query#

You can display the number of records returned by a query:


  • Learn more about RedisGraph in the Quickstart tutorial.