Goals If you are a JavaScript developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive it will introduce the different Drivers and link to the relevant resources. Prerequisites You should be… Learn More →

Goals
If you are a JavaScript developer, this guide provides an overview of options for connecting to Neo4j. While this guide is not comprehensive it will introduce the different Drivers and link to the relevant resources.
Prerequisites
You should be familiar with graph database concepts and the property graph model. You should have installed Neo4j and made yourself familiar with our Cypher Query language.
Intermediate


Neo4j for JavaScript Developers

nodejs

The standalone Neo4j-Server can be installed on any machine and then accessed via its HTTP API.

Below we show how you can use something as simple as the request module to send queries to and receive responses from Neo4j.

You can also choose to leverage one of the existing drivers for Neo4j which wrap that protocol in a more convenient API for you.

Follow the tips below to get you started.

The Example Project

It is a small one page webapp for our movies database. The front-end page is the same for all drivers, it consists of a movie search, detail info and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from the different languages and drivers.

You can learn more about our small, consistent example project across many different language drivers here. You find the implementations for all drivers as individual GitHub repositories, that you can clone and deploy directly.

Using the HTTP-Endpoint directly

You can use something as simple as the request node-module to send queries to and receive responses from Neo4j. The endpoint protocol and formats are explained in detail in the Neo4j Manual. It enables you do to much more, e.g. sending many statements per request or keeping transactions open across multiple requests.

Here is a very simple example:

Simple Function Accessing the Remote Endpoint
var r=require("request");
var txUrl = "http://localhost:7474/db/data/transaction/commit";
function cypher(query,params,cb) {
  r.post({uri:txUrl,
          json:{statements:[{statement:query,parameters:params}]}},
         function(err,res) { cb(err,res.body)})
}
Running the Function
var query="MATCH (n:User) RETURN n, labels(n) as l LIMIT {limit}"
var params={limit: 10}
var cb=function(err,data) { console.log(JSON.stringify(data)) }

cypher(query,params,cb)

{"results":[
  {"columns":["n","l"],
   "data":[
     {"row":[{"name":"Aran"},["User"]]}
    ]
  }],
 "errors":[]}

Seraph

Seraph is a comprehensive, well documented driver for Neo4j, which supports all Neo4j features and provides not only Neo4j connection support, but extensive lifecycle handling. The additional extensions seraph-model and seraph-resource allow you to quickly load and persist your models and integrate seraph-model resolution into your express routes with a base-controller for CRUD operations. With disposable-seraph you can manage a disposable Neo4j-instance for automatic testing.

cypher-stream

Neo4j cypher queries as node object streams.

Transactions are duplex streams that allow you to write query statements then commit or roll back the written queries.

To get a stream per statement, just pass a callback function with the statement object. This works for regular cypher calls and transactions.

node-neo4j (Thingdom)

Most widely used Node.js driver for Neo4j.

node-neo4j (philipkueng)

Neo4j REST API wrapper for Node.js Well maintained library, has been around since 2012.

Meteor.js

meteor logo

Meteor is a complete open source platform for building web and mobile apps in pure JavaScript.

Finally a Neo4j driver for Meteor is available.

Dmitriy wrapped node-neo4j to be usable with Meteor and also provided a pseudo-reactive driver to support the life-query functionality.

Neo4j Dart

dart logo

A Neo4j driver for Dart. Both a simple driver and an OGM (Object Graph Mapper) is provided in separate libraries.

Other Drivers

neo4j-js

A Node.js (pure JavaScript) client library for accessing neo4j databases with batch support.

node-neo4j-embedded

Node.js driver for the embedded Neo4j Database, it accesses the datatabase API through the JVM-integration directly. Also supports HA Setups.

Note: This is not idiomatic Javascript. For performance reasons it stays as close to the original Java API as possible.