Ping node output type not consistent

When a ping node is used, if it is successful in pinging, it returns time (number) for ping, however if not it returns a boolean (false). So output is either a boolean or a number. That makes it bit cumbersome to process the output (i.e. using a RBE node to check if a target is not accessible or becomes accessible again). Would it make sense to have payload type be consistent. i.e.

  1. either have a negative number if host is not reachable and a positive number with actual ping time if successful.
  2. or true/false if ping is successful/failed and a separate value for ping time ?

Since false == 0 you can just check payload is > 0.
Or msg.payload !== false. Alternatively, check typeof payload == "number"

1 Like


The ping node is written to use the users operating systems commands for ping. This is not all done in JS. Because the command can fail due to timing out, or error code, response false is used to control the response to node-red. Making something false in JS is useful to keep code down because you can place a var in a if statement.

var result = false;
if (result) {do stuff here if its not false}

this way if the command fails or times out no result(value of ping) replaces the result that was set to false.

If you would like to contribute and add a bunch of logic for all the user OS's and cases that cover it feel free to contribute --- > node-red-nodes/88-ping.js at master · node-red/node-red-nodes · GitHub

I like the way ping node is now and have no want to add a bunch of over head code to cover the issue you described. But feel free to offer a pull request to the big wigs and see if they like your path/solution.

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.