# Custom traversal via node.js API

**URL:** <https://community.neo4j.com/t/custom-traversal-via-node-js-api/34844>\
**Category:** Neo4j Graph Platform\
**Tags:** cypher, graph, javascript\
**Created:** [March 8, 2021, 8:59am UTC](https://community.neo4j.com/t/custom-traversal-via-node-js-api/34844 "2021-03-08T08:59:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![shahar1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shahar1/32/14486_2.png) [@shahar1](https://community.neo4j.com/u/shahar1)\
**Post date:** [March 8, 2021, 8:59am UTC](https://community.neo4j.com/t/custom-traversal-via-node-js-api/34844/1 "2021-03-08T08:59:52Z")

</div>

Hi,

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

 ![Screen Shot 2021-03-08 at 10.43.57](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/5/4/54e811b5586f0090a547d75505a827bb3c1281e8.jpeg)

Red nodes represent CIDRs, for example 10.0.0.0/27, 10.0.0.0/28, etc.  
Brown nodes represent that /32 IPs, for example 10.0.0.0/32, 10.0.0.1/32, 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

Thanks
