Skip to main content
Version: 2.5.1

JavaScript quick start

At the end of this guide, you will have created a simple JavaScript Hello, World! program that connects to the Memgraph database and executes simple queries.


Running queries directly from a web browser is not recommended because of additional requirements and possible performance issues. In other words, we encourage you to use server-side libraries and clients for top performance whenever possible.


To follow this guide, you will need:

  • A running Memgraph instance. If you need to set up Memgraph, take a look at the Installation guide.
  • A basic understanding of graph databases and the property graph model.

Basic Setup

Let's jump in and connect a simple program to Memgraph.

1. Create a new directory for your application, for example /MyApp and position yourself in it.

2. To make the actual program, create a program.html file and add the following code:

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8" />
<title>Javascript Browser Example | Memgraph</title>
<script src=""></script>
<p>Check console for Cypher query outputs...</p>
const driver = neo4j.driver(
neo4j.auth.basic("", "")

(async function main() {
const session = driver.session();

try {
await"MATCH (n) DETACH DELETE n;");
console.log("Database cleared.");

await"CREATE (alice:Person {name: 'Alice', age: 22});");
console.log("Record created.");

const result = await"MATCH (n) RETURN n;");

console.log("Record matched.");
const alice = result.records[0].get("n");
const label = alice.labels[0];
const name =["name"];
const age =["age"];

if (label != "Person" || name != "Alice" || age != 22) {
console.error("Data doesn't match.");

console.log("Label: " + label);
console.log("Name: " + name);
console.log("Age: " + age);
} catch (error) {
} finally {


3. Open the program.html file in your browser and look for the output in the console.

You should see an output similar to the following:

Database cleared.
Record created.
Record matched.
Label: Person
Name: Alice
Age: 22

Where to next?

For real-world examples of how to use Memgraph, we suggest you take a look at the Tutorials page. You can also browse through the How-to guides section to get an overview of all the functionalities Memgraph offers.