Skip to content

JsNode

Represents a graph node returned from queries or createNode().

Properties

Property Type Description
id number Internal node ID
labels string[] Node labels

Methods

get()

Get a property value by key. Returns undefined if the property doesn't exist.

get(key: string): any
const node = db.getNode(0);
console.log(node.get('name'));  // 'Alix'
console.log(node.get('missing'));  // undefined

properties()

Get all properties as a plain object.

properties(): object
const props = node.properties();
console.log(props);  // { name: 'Alix', age: 30 }

hasLabel()

Check if the node has a specific label.

hasLabel(label: string): boolean
node.hasLabel('Person');  // true
node.hasLabel('Animal');  // false

toString()

String representation of the node.

toString(): string
console.log(node.toString());  // '(:Person {id: 0})'

Example

// From query results
const result = await db.execute('MATCH (p:Person) RETURN p');
for (const node of result.nodes()) {
  console.log(`${node.id}: ${node.labels.join(':')} - ${node.get('name')}`);
}

// Direct creation
const node = db.createNode(['Person', 'Employee'], { name: 'Alix', age: 30 });
console.log(node.id);
console.log(node.labels);
console.log(node.properties());

// Label management
db.addNodeLabel(node.id, 'Manager');
db.removeNodeLabel(node.id, 'Employee');
console.log(db.getNodeLabels(node.id));  // ['Person', 'Manager']