Custom traversal via node.js API


I am building a tree-like graph of network based on CIDRs, like this (simplified) example:

Red nodes represent CIDRs, for example,, etc.
Brown nodes represent that /32 IPs, for example,, etc.

Due to the structure of the tree, each red node has exactly two CIDR nodes children.

I want to traverse the graph, starting from a given CIDR node X, and dynamically traverse its children based on some criteria.

Specifically, I'm trying to understand how I can give neo4j custom rules to traverse by, and not just "find all paths" or something like that.

I saw that Java has something called traversal framework, but I couldn't understand how I can use it from javascript, and also didn't really understand how I can give it custom rules.

My main goal is that for each node in the traversal, I will be given that node as a parameter so I can return the right path that neo4j should take to proceed with the traversal, if at all.

Is this possible via sub query? or some other way