Skip to content

README improvements #186

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 5, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ To get the latest stable release omit `@next` part altogether or use `@latest` i
```javascript
var neo4j = require('neo4j-driver').v1;
```
Driver instance should be closed when Node.js application exits:

```javascript
driver.close();
```

otherwise application shutdown might hang or it might exit with a non-zero exit code.

## Include in web browser

Expand All @@ -46,13 +53,33 @@ This will make a global `neo4j` object available, where you can access the `v1`
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));
```

It is not required to explicitly close the driver on a web page. Web browser should gracefully close all open
WebSockets when the page is unloaded. However, driver instance should be explicitly closed when it's lifetime
is not the same as the lifetime of the web page:

```javascript
driver.close();
```

## Usage examples

```javascript

// Create a driver instance, for the user neo4j with password neo4j.
// It should be enough to have a single driver per database per application.
var driver = neo4j.driver("bolt://localhost", neo4j.auth.basic("neo4j", "neo4j"));

// Register a callback to know if driver creation was successful:
driver.onCompleted = function() {
// proceed with using the driver, it was successfully instantiated
};

// Register a callback to know if driver creation failed.
// This could happen due to wrong credentials or database unavailability:
driver.onError = function(error) {
console.log('Driver instantiation failed', error);
};

// 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();
Expand Down Expand Up @@ -122,8 +149,18 @@ if (success) {
console.log('rolled back');
tx.rollback();
}

// Close the driver when application exits
driver.close();
```

Subscriber API allows following combinations of `onNext`, `onCompleted` and `onError` callback invocations:
* zero or more `onNext` followed by `onCompleted` when operation was successful. `onError` will not be invoked
in this case
* zero or more `onNext` followed by `onError` when operation failed. Callback `onError` might be invoked after
couple `onNext` invocations because records are streamed lazily by the database. `onCompleted` will not be invoked
in this case

## Building

npm install
Expand Down