npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kpdecker/neo4j-driver

v1.1.1

Published

Connect to Neo4j 3.0.0 and up from JavaScript

Downloads

5

Readme

Neo4j Driver for Javascript

A database driver for Neo4j 3.0.0+.

Find detailed docs at alpha.neohq.net.

Include module in Node.js application

npm install neo4j-driver
// or
bower install neo4j-driver
var neo4j = require('neo4j-driver');

Include in web browser

We build a special browser version of the driver, which supports connecting to Neo4j over WebSockets.

<script src="lib/browser/neo4j-web.min.js"></script>

This will make a global neo4j object available, where you can access the v1 API at neo4j.v1:

var driver = neo4j.v1.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));

Usage examples


// Create a driver instance, for the user neo4j with password neo4j.
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));

// Create a session to run Cypher statements in.
// Note: Always make sure to close sessions when you are done using them!
var session = driver.session();

// Run a Cypher statement, reading the result in a streaming manner as records arrive:
session
  .run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
  .subscribe({
    onNext: function(record) {
      console.log(record);
    },
    onCompleted: function() {
      // Completed!
      session.close();
    },
    onError: function(error) {
      console.log(error);
    }
  });

// or
// the Promise way, where the complete result is collected before we act on it:
session
  .run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' })
  .then(function(result){
    result.records.forEach(function(record) {
      console.log(record);
    });

    // Completed!
    session.close();
  })
  .catch(function(error) {
    console.log(error);
  });

  //run statement in a transaction
  var tx = session.beginTransaction();
  tx.run("CREATE (alice {name : {nameParam} })", { nameParam:'Alice' });
  tx.run("MATCH (alice {name : {nameParam} }) RETURN alice.age", { nameParam:'Alice' });
  //decide if the transaction should be committed or rolled back
  var success = ...
  ...
  if (success) {
    tx.commit()
      .subscribe({
        onCompleted: function() {
          // Completed!
          session.close();
         },
         onError: function(error) {
           console.log(error);
          }
        });
   } else {
     //transaction is rolled black nothing is created in the database
     tx.rollback();
   }

Building

npm install
npm build

This produces browser-compatible standalone files under lib/browser and a Node.js module version under lib/. See files under examples/ on how to use.

Testing

./runTests.sh

This runs the test suite against a fresh download of Neo4j. Or npm test if you already have a running version of a compatible Neo4j server.

For development, you can have the build tool rerun the tests each time you change the source code:

gulp watch-n-test

Testing on windows

Running tests on windows requires PhantomJS installed and its bin folder added in windows system variable Path. To run the same test suite, run .\runTest.ps1 instead in powershell with admin right. The admin right is required to start/stop Neo4j properly as a system service. While there is no need to grab admin right if you are running tests against an existing Neo4j server using npm test.

A note on numbers and the Integer type

The Neo4j type system includes 64-bit integer values. However, Javascript can only safely represent integers between -(253 - 1) and (253 - 1). In order to support the full Neo4j type system, the driver includes an explicit Integer types. Any time the driver recieves an Integer value from Neo4j, it will be represented with the Integer type by the driver.

Write integers

Number written directly e.g. session.run("CREATE (n:Node {age: {age}})", {age: 22}) will be of type Float in Neo4j. To write the age as an integer the neo4j.int method should be used:

var neo4j = require('neo4j-driver').v1;

session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int(22)});

To write integers larger than can be represented as JavaScript numbers, use a string argument to neo4j.int:

session.run("CREATE (n {age: {myIntParam}})", {myIntParam: neo4j.int("9223372036854775807")});

Read integers

Since Integers can be larger than can be represented as JavaScript numbers, it is only safe to convert Integer instances to JavaScript numbers if you know that they will not exceed (253 - 1) in size:

var aSmallInteger = neo4j.int(123);
var aNumber = aSmallInteger.toNumber();

If you will be handling integers larger than that, you can use the Integer instances directly, or convert them to strings:

var aLargerInteger = neo4j.int("9223372036854775807");
var integerAsString = aLargerInteger.toString();

To help you work with Integers, the Integer class exposes a large set of arithmetic methods. Refer to the Integer API docs for details.