Get Started What is a GraphDB? GraphDB vs RDBMS GraphDB vs NOSQL Language Drivers Cypher Cypher Basics Build a Recommendation Engine Cypher Refcard Data Modeling Graph Data Modeling Guidelines Working with Data Neo4j Browser Visualization Importing Data into Neo4j Graph… 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.

But 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

You can find out more about our example projects for many different languages here, you can also access it via the GitHub repository for the Neo4j developer resources. Feel free to check them out.

It is a small one page webapp for our movies database. The front-end is the same for all drivers, just the backends show you how to connect to Neo4j from the different languages and drivers.

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 statments per requests or keeping transactions open across multiple requests.

Here is a 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":[]}

node-neo4j

Most widely used Node.js driver for Neo4j.

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. Supports HA Setups, API is built to be as close to the Java API as possible.