As you have landed on this article, I assume you already know what neo4j or graph database is. This article describes how to expose express.js apis to do a very basic write and read operation. You can do it without using express also.

Things to be known

  • Neo4J uses cypher query language.
  • Neo4J provides very nice rest apis to interact without any intermediate driver.
  • Though it has a driver. You can use this driver also to make development simpler.
  • This article shows how to node neo4j using its http endpoints and the last paragraph shows an example to use the thingdom driver.

So scaffold your node project first. you can use npm init or you can directly clone or fork our github repo to start with.

Starting neo4j server

Hope you already know how to start a neo4j server. You need to install neo4j. The community edition is free. After installing start the software and it will run the database on port 7474 by default.

app.js basic setup

so we just exposed two http rest apis with express.js and both of them are empty at the moment.

Api authentication

Every single http rest call to neo4j apis need an authentication token in the header which is nothing but the base64 encryption of your username:password string. Below is an example to do that and also a function which will do the database operation for us.

Below is a function which makes the call to neo4j database with request module of node.js (you can also use node’s http.request for the same purpose)

create operation

read operation

Parameterized read write

npm plugins for neo4j

You can also use plugins to perform the calls in a more sophisticated way. Neo4j has it’s official node plugin. Below is an example how this plugin works