Duplicate of http request

Hi, I have do a function to list out the files from specific directory, and set a delete button besides the file name,

when user click the delete button, Node Red will delete the file and refresh the file list.

But the problem is , when I adjust the nodes and deploy the Node Red, and click the delete button, it will send 2 http request

below is my flow:
flows (1).json (7.8 KB)

So if I got you right, you don´t want that the http request is sent twice?
As an workaround you could use the delay node, to allow only 1 message per xxx milliseconds.

but the weird thing is,

when I first time configure the node and deploy it, it works well.

on seconds time deploy, it call http request 2 times,

on my third time deploy, it call http request 3 times,

and so on.. no idea what's wrong with my node :rofl: :rofl:

you are not removing the listener when the node is closed (re-deployed) so every time you deploy you are adding another listener... so you will get one more call every time.

Or remove the endpoint and send the file to delete in the message.

[{"id":"79924ade966c2231","type":"ui_ui_control","z":"bf9e1e33.030598","name":"","events":"all","x":210,"y":920,"wires":[["7b08ec8c.a8edbc"]]},{"id":"7b08ec8c.a8edbc","type":"switch","z":"bf9e1e33.030598","name":"","property":"tab","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":360,"y":920,"wires":[["6bf7dcb2.b45944"]]},{"id":"6bf7dcb2.b45944","type":"change","z":"bf9e1e33.030598","name":"load files","rules":[{"t":"set","p":"files","pt":"msg","to":"files","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":230,"y":980,"wires":[["2d7e0d9c979f7bde"]]},{"id":"e4f12ff8.2a42b8","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"files","pt":"flow","to":"[\"one.txt\",\"two.txt\",\"three.txt\"]","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":1200,"wires":[["6bf7dcb2.b45944"]]},{"id":"b8b5bcde.097d48","type":"change","z":"bf9e1e33.030598","name":"delete file","rules":[{"t":"set","p":"files","pt":"flow","to":"[([$flowContext(\"files\")])[$!=$$.deleteFile]]","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":1060,"wires":[["6c5d7262.512e3c","6bf7dcb2.b45944"]]},{"id":"2d7e0d9c979f7bde","type":"ui_template","z":"bf9e1e33.030598","group":"67fa6f518a45aecb","name":"ui_temlplate - present download links on dashboard","order":1,"width":"6","height":"8","format":"<div><table>\n    <tr>\n        <th>Files</th><th></th><th></th>\n    </tr>\n    <tr ng-repeat=\"row in msg.files\">\n        <td>{{row}}</td>\n        <td> <a class=\"buttonDownload\"  href=\"/files/{{row}}\" target=\"_blank\">Download</a></td>\n        <td> <button class=\"buttonDelete\" ng-click=\"send({payload: row})\">delete</button></td>\n    </tr>\n</table></div>\n<style>\n.buttonDownload {\n  background-color: #4CAF50; /* Green */\n  color: #000000;\n  text-decoration: none;\n  padding: 5px 10px 5px;\n    }\n.buttonDelete {\n  background-color: red; /* Green */\n  color: #000000;\n  text-decoration: none;\n  padding: 5px 10px 5px;\n}\n.buttonDelete:hover, .buttonDownload:hover {\n  background-color: blue; /* Green */\n  color: white;\n}   \n</style>\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":600,"y":980,"wires":[["d7ecc8e70ecf18d5","19c6fbdb.ff1c24"]],"info":"<script type=\"text/javascript\" charset=\"utf-8\">\n\n    $( document ).on( \"click\", \"a.delete\", function() {\n        \n        var url = \"/delete/\" + $(this).parent().siblings('td:first').html();\n        console.log(url)\n        const xhttp = new XMLHttpRequest();\n        xhttp.open(\"GET\", url);\n        xhttp.send();\n    }); \n\n</script>\n"},{"id":"56fadbd7.b1a614","type":"inject","z":"bf9e1e33.030598","name":"set files for testing","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":1200,"wires":[["e4f12ff8.2a42b8"]]},{"id":"49b5aa122be0acec","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OK","vt":"str"},{"t":"eq","v":"Cancel","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":580,"y":1060,"wires":[["b8b5bcde.097d48"],[]]},{"id":"6c5d7262.512e3c","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":750,"y":1120,"wires":[]},{"id":"d7ecc8e70ecf18d5","type":"debug","z":"bf9e1e33.030598","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":920,"wires":[]},{"id":"19c6fbdb.ff1c24","type":"change","z":"bf9e1e33.030598","name":"","rules":[{"t":"set","p":"deleteFile","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":250,"y":1060,"wires":[["b304b1ac8f5d9c15"]]},{"id":"b304b1ac8f5d9c15","type":"ui_toast","z":"bf9e1e33.030598","position":"dialog","displayTime":"","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"Cancel","raw":false,"className":"","topic":"Confirm to delete this file?","name":"Name","x":440,"y":1060,"wires":[["49b5aa122be0acec"]]},{"id":"67fa6f518a45aecb","type":"ui_group","name":"Humidity","tab":"ce5dd7b2afdbfd55","order":1,"disp":false,"width":"6","collapse":false,"className":"humidity"},{"id":"ce5dd7b2afdbfd55","type":"ui_tab","name":"Realtime Panel","icon":"mi-drag_indicator","order":1,"disabled":false,"hidden":false}]

[edit] Added the refresh of template and simulated file FS. Just replace the change nodes for FS nodes. Also some css for styling

it actually blow my mind as I thought event listener will be replaced by new listener upon node red re-deployed

thanks for sharing the information :pray:

thanks :+1: your solution are much simpler than mine

I will take some time to understand the concept