Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
neo4j-driver
Advanced tools
The neo4j-driver npm package is a driver for connecting to and interacting with a Neo4j database from a Node.js application. It provides a set of tools and APIs to perform various operations such as connecting to the database, executing Cypher queries, managing transactions, and handling results.
Connecting to Neo4j
This feature allows you to establish a connection to a Neo4j database using the Bolt protocol. You need to provide the database URL and authentication credentials.
const neo4j = require('neo4j-driver');
const driver = neo4j.driver('bolt://localhost:7687', neo4j.auth.basic('username', 'password'));
const session = driver.session();
Executing Cypher Queries
This feature enables you to execute Cypher queries against the connected Neo4j database. The example demonstrates running a simple query to match and return all nodes.
const result = await session.run('MATCH (n) RETURN n');
result.records.forEach(record => {
console.log(record.get(0));
});
Managing Transactions
This feature allows you to manage transactions, providing a way to commit or rollback operations as needed. The example shows how to create a node within a transaction and handle errors.
const tx = session.beginTransaction();
try {
await tx.run('CREATE (n:Person {name: $name})', { name: 'Alice' });
await tx.commit();
} catch (error) {
await tx.rollback();
throw error;
}
Handling Results
This feature provides methods to handle and process the results returned from Cypher queries. The example demonstrates accessing and logging the properties of a node from the query result.
const result = await session.run('MATCH (n) RETURN n');
const singleRecord = result.records[0];
const node = singleRecord.get(0);
console.log(node.properties);
The 'neo4j' npm package is another driver for interacting with Neo4j databases. It offers similar functionalities to 'neo4j-driver' but may have different API conventions and additional features. It is also designed to work with the Neo4j REST API.
The 'seraph' package is a Node.js library for interacting with Neo4j databases. It provides a higher-level abstraction over the Neo4j REST API, making it easier to work with nodes and relationships. Compared to 'neo4j-driver', it focuses more on simplifying common operations and providing a more intuitive API.
The 'neode' package is an Object Graph Mapper (OGM) for Neo4j, similar to an ORM for relational databases. It allows you to define models and interact with the database using those models. 'neode' provides a higher-level abstraction compared to 'neo4j-driver', making it easier to work with complex data structures.
An alpha-level database driver for Neo4j 3.0.0+.
Note: This is in active development, the API is not stable. Please try it out and give us feedback, but expect things to break in the medium term!
npm install neo4j-driver
var neo4j = require('neo4j-driver/v1');
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");
// Create a driver instance
var driver = neo4j.driver("bolt://localhost");
// 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(records){
records.forEach(function(record) {
console.log(record);
});
// Completed!
session.close();
})
.catch(function(error) {
console.log(error);
});
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.
./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
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
.
The Neo4j type system includes 64-bit integer values.
However, Javascript can only safely represent integers between -(2
53
- 1)
and (2
53
- 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.
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');
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")});
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 (2
53
- 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.
FAQs
The official Neo4j driver for Javascript
The npm package neo4j-driver receives a total of 123,127 weekly downloads. As such, neo4j-driver popularity was classified as popular.
We found that neo4j-driver demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.