Hello, World! program that connects to the Memgraph database and executes simple queries.
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.
- The newest version of Node.JS installed. Instructions on how to setup Node.JS can be found on the official website.
We'll be using Express.js to demonstrate how to connect to a running Memgraph instance. Express.js is a web application framework that enables us to create complete Node.js applications. If you don't wish to use it, the steps might be slightly different, but the code is most likely the same or very similar.
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. Create a
package.json file with the command:
3. Install Express.js and the Bolt driver in the
/MyApp directory while adding them to the dependencies list.
4. To make the actual program, create a
program.js file and add the following code:
5. Run the application with the following command:
You should see an output similar to the following:
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 Database functionalities section to get an overview of all the functionalities Memgraph offers.
Visit the Getting help page in case you run into any kind of problem or you have additional questions.