I want to get the shortest port distance between two node for every node we have two ports

Node.ports is a property that returns a collection – it is not a function.

part.ports.each(port => ...);