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 →
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.
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.
Overview
Neo4j for JavaScript Developers
Neo4j can be installed on any system and then accessed via its binary and HTTP APIs.
You can use the official binary driver for JavaScript (neo4j-driver) or connect via HTTP using the request module or any of our community drivers.
Neo4j Javascript Driver
The Neo4j JavaScript driver is officially supported by Neo4j and connects to the database using the binary protocol. It aims to be minimal, while being idiomatic to JavaScript, allowing you to subscribe to a stream of responses, errors and completion events.
npm install neo4j-driver@1.0.2 var neo4j = require('neo4j-driver').v1;
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
var session = driver.session();
session
.run( "CREATE (a:Person {name:'Arthur', title:'King'})" )
.then( function()
{
return session.run( "MATCH (a:Person) WHERE a.name = 'Arthur' RETURN a.name AS name, a.title AS title" )
})
.then( function( result ) {
console.log( result.records[0].get("title") + " " + result.records[0].get("name") );
session.close();
driver.close();
}) Name | Version | Authors |
neo4j-driver | 1.0.2 | The Neo4j Team |
The Example Project
The Neo4j example project is a small, one page webapp for the movies database built into the Neo4j tutorial. The front-end page is the same for all drivers: movie search, movie details, and a graph visualization of actors and movies. Each backend implementation shows you how to connect to Neo4j from each of the different languages and drivers.
You can learn more about our small, consistent example project across many different language drivers here. You will find the implementations for all drivers as individual GitHub repositories, which you can clone and deploy directly.
Neo4j Community Drivers
| The drivers below have been thankfully contributed by the Neo4j community. Many of these are fully featured and well maintained. But we don’t take any reponsibility for their fitness for use with the most recent Versions of Neo4j. |
There is a nice, more detailed intro article on modulus on how to use Neo4j from Javascript.
node-neo4j (Thingdom)
Most widely used Node.js driver for Neo4j. This driver aims to be the most robust, comprehensive, and battle-tested community driver available. It’s run in production by FiftyThree to power Paper and Mix.
Features
- Cypher queries, parameters, batching, and transactions
- Arbitrary HTTP requests, for custom Neo4j plugins
- Custom headers, for high availability, application tracing, query logging, and more
- Precise errors, for robust error handling from the start
- Configurable connection pooling, for performance tuning & monitoring
- Thorough test coverage with >100 tests
- Continuously integrated against multiple versions of Node.js and Neo4j
Authors | Aseem Kishore & Daniel Gasienica |
Package | |
Source | |
Example | |
Docs | |
API | |
Forum |
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.
Authors | |
Package | |
Source |
- [cypher-stream on GitHub]
- Author:
- that streams from database to client.
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.
Authors | |
Package | |
Source | |
Model | |
Resource | |
Disposable |
simple-neo4j
This is a simple neo4j pure javascript database driver. It takes in one or more queries, commits them to the database in a single transaction, and parses the database result into a simple and easy native javascript object, of course the parser can be disabled if desired.
simpleNeo4J.execute('MATCH (n:Movie) RETURN count(*)')
.then(function(result)
{
result.firstValue === 26;
}); Authors | |
Package | |
Source |
Meteor.js – Package ccorcos:neo4j
Meteor is a complete open source platform for building web and mobile apps in pure JavaScript.
Chet and Sam Corcos created the ccorcos:neo4j package that integrates Meteor well with Neo4j including reactivity and query-reevaluation on data changes.
Both wrote and presented about it and Chet provided insight into an example application for event feeds, written with Meteor and Neo4j as a stack.
Authors | |
Package | |
Source |
Ostrio – Meteor.js – Driver
Dmitriy wrapped node-neo4j to be usable with Meteor and also provided a pseudo-reactive driver to support the life-query functionality.
Authors | |
Package | |
Example |
Neo4j Dart
A Neo4j driver for Dart. Both a simple driver and an OGM (Object Graph Mapper) is provided in separate libraries.
Authors | |
Package | |
Source | |
Example | |
Docs |
node-neo4j (philipkueng)
Neo4j REST API wrapper for Node.js. Well maintained library, has been around since 2012.
@subvertallmedia I ended up using https://t.co/sh54JoVDHq which worked fine. Also the neo4j shell was pretty good!
— John Resig (@jeresig) January 27, 2015 Authors | |
Package | |
Source | |
Docs |
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:
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)})
} 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":[]} 





5 Trackbacks