Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

The Neo4J client for Node.js and the Browser

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .gitmodules
Octocat-spinner-32 .npmignore
Octocat-spinner-32 Cakefile
Octocat-spinner-32 LICENSE.md
Octocat-spinner-32 README.md
Octocat-spinner-32 neo4js.js
Octocat-spinner-32 package.json
README.md

Neo4js

The Neo4J client for Node.js and the Browser.

Install

Node.js

npm install neo4js

Browser

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://github.com/viatropos/neo4js/raw/master/neo4js.js"></script>

Note that neo4js.js (temporarily) requires jQuery to run in the browser.

Quick example

neo4j = require("neo4js")

graph = new neo4j.Database("http://localhost:7474")

graph.node name: "Lisa", (error, lisa) ->
  graph.node name: "Bob", (error, bob) ->
    graph.rel lisa, "LOVES", bob, reason: "All the bling he got.", (error, relationship) ->
      # Get the end node of the LOVES relationship
      name = bob.get("name")
      # Change a property like this
      bob.set("name", "Steven")
      bob.save (error, steven) ->
        name = steven.get("name")

API

http://docs.neo4j.org/chunked/stable/rest-api.html

database = new neo4j.Database("http://localhost:7474")
database.node properties (error, node)
database.relationship fromNode, type, toNode, data, (error, relationship) # or database.rel
database.getReferenceNode (error, node) # or database.getRoot
database.getAvailableRelationshipTypes (error, types)
database.getServiceDefinition (error, definition)
database.getDiscoveryDocument (error, document)

node = new neo4j.Node({self: url}, database)
node.save (error)
node.fetch (error, newNode)
node.remove (error)
node.getCreateRelationshipUrl()
node.traverse traversal, returnType, (error, nodes)
node.getRelationships dir, types, (error, relationships)

relationship = new neo4j.Relationship({start: startNode, end: endNode}, database)
relationship.save (error)
relationship.fetch (error)
relationship.remove (error)
relationship.getStartNode (error, node)
relationship.getEndNode (error, node)
relationship.isStartNode node
relationship.getOtherNode node, (error, otherNode)

# common to both nodes and relationships
nodeOrRelationship.getSelf() #=> url
nodeOrRelationship.exists()
nodeOrRelationship.has(key)
nodeOrRelationship.get(key)
nodeOrRelationship.set(key, value)
nodeOrRelationship.getProperties()
nodeOrRelationship.setProperties(key: "value")

Run Tests

First, find your NEO4J_HOME path.

$ neo4j info
Neo4j Server is not running
Using Java version: CurrentJDK
NEO4J_HOME:        /usr/local/Cellar/neo4j/community-1.5/libexec
NEO4J_SERVER_PORT: 7474
...

If you used HomeBrew to install Neo4j, it will be similar to above: /usr/local/Cellar/neo4j/community-{VERSION}/libexec. Now just download https://github.com/jexp/neo4j-clean-remote-db-addon and place it in NEO4J_HOME/plugins. Finally, add these two lines to NEO4J_HOME/conf/neo4j-server.properties:

org.neo4j.server.thirdparty_jaxrs_classes=org.neo4j.server.extension.test.delete=/db/data/cleandb
org.neo4j.server.thirdparty.delete.key=secret-key

Then you can issue

curl -X DELETE http://localhost:7474/db/data/cleandb/secret-key

to delete the graph database without restarting the server.

Now, start the Neo4j server.

neo4j start

Finally, run the tests.

npm test

Client Tests

node test/client -p 3000
# http://localhost:3000

Contribute

Compile CoffeeScript for client and server:

cake coffee
Something went wrong with that request. Please try again.