Search for function nodes with certain code?

Love the new junction node. Previously I used function nodes for this purpose, i.e. just created a function node with return msg;

In all the new snazziness, is there a way to search for function nodes that just contain this line?

unfortunately not - you will get all functions with that line (that will likely be the majority of them)

You could try exporting the entrie flow (use the pretty format) and then opening it in a text editor.
Next search for 'return msg' and when you find one, grab the id of the msg and in NR you can search for that using the ctrl-f (find).

{"id":"d2d2785eb1a00b17",  <==== this 'd2d2785eb1a00b17' will be what you search on
"type":"function",
"z":"13040b63810e7b1b",
"name":"foo",
"func":"\nreturn msg;",
"outputs":1,
"noerr":0,
"initialize":"",
"finalize":"",
"libs":[],
"x":270,
"y":280,
"wires":[[]]},

Each one will need it's own search.

you could also load the flow file into msg.payload and search the full array, using a change node and JSONata

$$.payload[$length($.func)<15].id

which should return an array of all id's where function property is less than 15 characters.
e,g.

[{"id":"6b47984.fc07568","type":"change","z":"aaa27ee4852b402b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$$.payload[$length($.func)<15].id","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":380,"wires":[["f5f3d227.61fc28"]]},{"id":"8f14c8ad.4c12f","type":"inject","z":"aaa27ee4852b402b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"id\":\"aaa27ee4852b402b\",\"type\":\"tab\",\"label\":\"Flash LED\",\"disabled\":false,\"info\":\"\"},{\"id\":\"8fc2f37d8b8d1eba\",\"type\":\"delay\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"pauseType\":\"delayv\",\"timeout\":\"400\",\"timeoutUnits\":\"milliseconds\",\"rate\":\"1\",\"nbRateUnits\":\"1\",\"rateUnits\":\"second\",\"randomFirst\":\"1\",\"randomLast\":\"5\",\"randomUnits\":\"seconds\",\"drop\":false,\"x\":1020,\"y\":160,\"wires\":[[\"77f31641.d63258\"]]},{\"id\":\"b8e91e92.ccca58\",\"type\":\"split\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"splt\":\"1\",\"spltType\":\"len\",\"arraySplt\":1,\"arraySpltType\":\"len\",\"stream\":false,\"addname\":\"\",\"x\":690,\"y\":160,\"wires\":[[\"456471b9.2667e\"]]},{\"id\":\"b71e99df.9661f\",\"type\":\"debug\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"active\":true,\"tosidebar\":true,\"console\":false,\"tostatus\":false,\"complete\":\"false\",\"statusVal\":\"\",\"statusType\":\"auto\",\"x\":870,\"y\":120,\"wires\":[]},{\"id\":\"456471b9.2667e\",\"type\":\"change\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"rules\":[{\"t\":\"set\",\"p\":\"payload\",\"pt\":\"msg\",\"to\":\"$number($$.payload) = 1\",\"tot\":\"jsonata\"},{\"t\":\"set\",\"p\":\"delay\",\"pt\":\"msg\",\"to\":\"$number($$.topic) * ($$.parts.index)\",\"tot\":\"jsonata\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":850,\"y\":160,\"wires\":[[\"8fc2f37d8b8d1eba\"]]},{\"id\":\"33d07144.1f6546\",\"type\":\"inject\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"props\":[{\"p\":\"payload\"},{\"p\":\"topic\",\"vt\":\"str\"}],\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"onceDelay\":0.1,\"topic\":\"400\",\"payload\":\"3\",\"payloadType\":\"str\",\"x\":370,\"y\":60,\"wires\":[[\"5ba6739.ccddc8c\"]]},{\"id\":\"951a4dc9.b79f38\",\"type\":\"inject\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"props\":[{\"p\":\"payload\"},{\"p\":\"topic\",\"vt\":\"str\"}],\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"onceDelay\":0.1,\"topic\":\"200\",\"payload\":\"5\",\"payloadType\":\"str\",\"x\":350,\"y\":160,\"wires\":[[\"21022e92.635112\"]]},{\"id\":\"3fb67766.cbb2c8\",\"type\":\"inject\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"props\":[{\"p\":\"payload\"},{\"p\":\"topic\",\"vt\":\"str\"}],\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"onceDelay\":0.1,\"topic\":\"200\",\"payload\":\"1010101010\",\"payloadType\":\"str\",\"x\":360,\"y\":280,\"wires\":[[\"dd89688f.c7b02\"]]},{\"id\":\"21022e92.635112\",\"type\":\"change\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"rules\":[{\"t\":\"set\",\"p\":\"payload\",\"pt\":\"msg\",\"to\":\"$substring(\\\"1010101010101010101010101010101010101010101010101010101010\\\", 0 , $number($$.payload) * 2)\",\"tot\":\"jsonata\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":520,\"y\":160,\"wires\":[[\"b8e91e92.ccca58\"]]},{\"id\":\"5ba6739.ccddc8c\",\"type\":\"function\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"func\":\"const timeout = ((count,time) => setTimeout(() => {\\n        node.send({payload: count % 2 === 0})\\n        }, Number(time) * count\\n    ))\\nfor(let i = 0; i < Number(msg.payload) * 2; i++) {\\n    timeout(i, msg.topic);\\n}\\nreturn null;\\n\",\"outputs\":1,\"noerr\":0,\"initialize\":\"\",\"finalize\":\"\",\"libs\":[],\"x\":550,\"y\":60,\"wires\":[[\"91d2c758.a70948\"]]},{\"id\":\"91d2c758.a70948\",\"type\":\"debug\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"active\":true,\"tosidebar\":true,\"console\":false,\"tostatus\":false,\"complete\":\"false\",\"statusVal\":\"\",\"statusType\":\"auto\",\"x\":740,\"y\":60,\"wires\":[]},{\"id\":\"cf054a62.3a36b8\",\"type\":\"inject\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"props\":[{\"p\":\"payload\"},{\"p\":\"topic\",\"vt\":\"str\"}],\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"onceDelay\":0.1,\"topic\":\"400\",\"payload\":\"2\",\"payloadType\":\"str\",\"x\":350,\"y\":120,\"wires\":[[\"f7550e34.44162\"]]},{\"id\":\"f7550e34.44162\",\"type\":\"function\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"func\":\"for(let i = 0; i < Number(msg.payload) * 2; i++) {\\n    node.send({payload: i % 2 === 0, delay: Number(msg.topic) * i})\\n}\\nreturn null;\",\"outputs\":1,\"noerr\":0,\"initialize\":\"\",\"finalize\":\"\",\"libs\":[],\"x\":510,\"y\":120,\"wires\":[[\"5168b6da.1baa78\"]]},{\"id\":\"5168b6da.1baa78\",\"type\":\"delay\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"pauseType\":\"delayv\",\"timeout\":\"400\",\"timeoutUnits\":\"milliseconds\",\"rate\":\"1\",\"nbRateUnits\":\"1\",\"rateUnits\":\"second\",\"randomFirst\":\"1\",\"randomLast\":\"5\",\"randomUnits\":\"seconds\",\"drop\":false,\"x\":680,\"y\":120,\"wires\":[[\"b71e99df.9661f\"]]},{\"id\":\"77f31641.d63258\",\"type\":\"debug\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"active\":true,\"tosidebar\":true,\"console\":false,\"tostatus\":false,\"complete\":\"false\",\"statusVal\":\"\",\"statusType\":\"auto\",\"x\":1190,\"y\":220,\"wires\":[]},{\"id\":\"dd89688f.c7b02\",\"type\":\"split\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"splt\":\"1\",\"spltType\":\"len\",\"arraySplt\":1,\"arraySpltType\":\"len\",\"stream\":false,\"addname\":\"\",\"x\":530,\"y\":280,\"wires\":[[\"4e9cfb27.fb1334\"]]},{\"id\":\"4e9cfb27.fb1334\",\"type\":\"change\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"rules\":[{\"t\":\"set\",\"p\":\"payload\",\"pt\":\"msg\",\"to\":\"$number($$.payload) = 1\",\"tot\":\"jsonata\"},{\"t\":\"set\",\"p\":\"delay\",\"pt\":\"msg\",\"to\":\"$number($$.topic) * ($$.parts.index)\",\"tot\":\"jsonata\"}],\"action\":\"\",\"property\":\"\",\"from\":\"\",\"to\":\"\",\"reg\":false,\"x\":690,\"y\":280,\"wires\":[[\"a94a5dce.fac198\"]]},{\"id\":\"a94a5dce.fac198\",\"type\":\"delay\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"pauseType\":\"delayv\",\"timeout\":\"400\",\"timeoutUnits\":\"milliseconds\",\"rate\":\"1\",\"nbRateUnits\":\"1\",\"rateUnits\":\"second\",\"randomFirst\":\"1\",\"randomLast\":\"5\",\"randomUnits\":\"seconds\",\"drop\":false,\"x\":860,\"y\":280,\"wires\":[[\"ea40d8ce.f01e1\"]]},{\"id\":\"ea40d8ce.f01e1\",\"type\":\"debug\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"active\":true,\"tosidebar\":true,\"console\":false,\"tostatus\":false,\"complete\":\"false\",\"statusVal\":\"\",\"statusType\":\"auto\",\"x\":1030,\"y\":280,\"wires\":[]},{\"id\":\"8f14c8ad.4c12f\",\"type\":\"inject\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"props\":[{\"p\":\"payload\"},{\"p\":\"topic\",\"vt\":\"str\"}],\"repeat\":\"\",\"crontab\":\"\",\"once\":false,\"onceDelay\":0.1,\"topic\":\"\",\"payload\":\"\",\"payloadType\":\"date\",\"x\":460,\"y\":380,\"wires\":[[]]},{\"id\":\"dacc79f0.67f2e8\",\"type\":\"function\",\"z\":\"aaa27ee4852b402b\",\"name\":\"\",\"func\":\"\\nreturn msg;\",\"outputs\":1,\"noerr\":0,\"initialize\":\"\",\"finalize\":\"\",\"libs\":[],\"x\":380,\"y\":240,\"wires\":[[]]}]","payloadType":"json","x":440,"y":380,"wires":[["6b47984.fc07568"]]},{"id":"f5f3d227.61fc28","type":"debug","z":"aaa27ee4852b402b","name":"","active":true,"tosidebar":true,"console":false," clicked wrong reply button":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":380,"wires":[]}]

[edit] Sorry @Steve-Mcl clicked wrong reply button.

1 Like

A little script to run against your flows file (on a Linux machine, or WSL, Cygwin etc).

As with @zenofmud's suggestion, the file should be in "Pretty Print" format. (flowFilePretty: true, in settings.js).

It's far from foolproof but it should give you a list of function nodes containing just return msg or \nreturn msg.

On my Raspberry Pi it gives this

"ec3fbe435ba643b0",        "func": "\nreturn msg;",
"8188766be3fe8981",        "func": "return msg;",

Edit - This version will also list all nodes who's label is not shown, it's likely to produce duplicate output

#! /bin/bash
FILE=/home/pi/.node-red/flows.json

awk ' /"id":/ { lastid = $2}
/"l": false/ { print lastid $0 }
/"func": "return msg/ { print lastid $0 }
/"func": "\\nreturn msg/ { print lastid $0 } ' $FILE
1 Like

Lol - no worries. I did start to edit my post but I got as far as typing "but you can search the json" and then got distracted by the smell of coffee and never finished it - but you guys have offered some good ideas.

1 Like

Super response all, many thanks!

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