Neode is a Neo4j OGM for Node JS designed to take care of the CRUD boilerplate involved with setting up a neo4j project with Node. Just install, set up your models and go.
npm install --save neode
// index.js;const instance = 'bolt://localhost:7474' 'username' 'password';
To initiate Neode in enterprise mode and enable enterprise features, provide a true variable as the fourth parameter.
// index.js;const instance = 'bolt://localhost:7474' 'username' 'password' true;
npm i --save dotenv
// .env NEO4J_PROTOCOL=bolt NEO4J_HOST=localhost NEO4J_USERNAME=neo4j NEO4J_PASSWORD=neo4j NEO4J_PORT=7687
// index.js;const instance = ;
You can use the
with() method to load multipe models at once.
const neode =;
You can load a directory of models by calling the
// models/Person.jsmoduleexports =id:type: 'uuid'primary: truename: 'string'
Neode revolves around the notion of node definitions, or
Models. To interact with the graph, you will need to define a node, identified by a
name and with a
schema of properties.
Validation is provided by Joi. Certain data types (float, integer, boolean) will also be type cast.
Relationships can be created in the schema or defined retrospectively.
You can inherit the schema of a class and extend by calling the extend method.
instance.extend(original, new, schema)
Batch queries run within their own transaction. Transactions can be sent as either a string or an object containing
instance.all(label, properties) instance.model(label).all(properties)
instanceall'Person' name: 'Adam' name: 'ASC' id: 'DESC' 1 0
instance.findById(label, id) instance.model(label).findById(id)
Neode will work out the model's primary key and query based on the supplied value.
instance.find(label, id) instance.model(label).find(id)
instance.first(label, key, value) instance.first(label).first(key, value)
instance.first(label, properties) instance.first(label).first(properties)
Nodes are merged based on the indexes and constraints.
If you know the properties that you would like to merge on, you can use the
You can update a Node instance directly by calling the
You can relate two nodes together by calling the
Note: when creating a relationship defined as
to() properties will be inversed regardless of which model the relationship is created by.
You can delete a Node instance directly by calling the
Neode comes bundled with a query builder. You can create a Query Builder instance by calling the
query() method on the Neode instance.
const builder = instance;
Once you have a Builder instance, you can start to defining the query using the fluent API.
For query examples, check out the Query Builder Test suite.
You can get the generated cypher query by calling the
build() method. This method will return an object containing the cypher query string and an object of params.
const query params = builder;instance;
You can execute a query by calling the
execute() method on the query builder.
Neode will install the schema created by the constraints defined in your Node definitions.
exists constraints will only be created when running in enterprise mode. Attempting to create an exists constraint on Community edition will cause a
Neo.DatabaseError.Schema.ConstraintCreationFailed to be thrown.
Dropping the schema will remove all indexes and constraints created by Neode. All other indexes and constraints will be left intact.