Remove All / Selected Global Variables from localfilesystem / memory store

Node-Red have no option to remove global variables store (either from memory or localfilesystem)

This script gives you a clickable button to clear all once or have a IF selection to remove (Like if you want to remove all variables starting with "EN", or Has words "Temp" or Has "XX" in the end of the variable name.

The Script loads global.json (File for all global variables) and process it,

make it a js array or variables and removes all variables from Node-Red by setting global

Created by [email protected]

[{"id":"35115b88.ea6db4","type":"debug","z":"b003eab5.e1bff8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":860,"wires":[]},{"id":"86b2af35.8f2cd","type":"inject","z":"b003eab5.e1bff8","name":"Push to Remove All Global Variables","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":740,"wires":[["8c97c820.1a9518"]]},{"id":"c31b99c2.a89448","type":"function","z":"b003eab5.e1bff8","name":"Delete all variables from Node-Red Store (localfilesystem or memory)","func":"//Remove all global variables context storage\n\n//Loads the global.json file from Node-Red localfilesystem store\n\nvar text = \"\";\n\nvar jsa = msg.payload; // (The File in Node will give json store data)\n\nvar obj = JSON.parse(jsa); // Convert Variables from json to javascript\n\n//Process all variable names\nfor (var x in obj){\n\n//partial removing matching function\n//if(x.indexOf(\"fan01\")>=0){\n\ntext += \"Removed -> \" + x + \"\\r\\n\";\n\n//default store\nglobal.set(x,undefined);\n\n//specify store: Specify localfilesystem store name or remove for default store\n//global.set(x,undefined,\"storage\");\n\n\n//}\n\n}\n\n//Output in Debug Window\nmsg.payload = text;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":860,"wires":[["35115b88.ea6db4"]]},{"id":"8c97c820.1a9518","type":"file in","z":"b003eab5.e1bff8","name":"Global Variables File (Change Username / File Path)","filename":"/home/pi/.node-red/context/global/global.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":400,"y":800,"wires":[["c31b99c2.a89448"]]},{"id":"c73b1187.2c7e7","type":"comment","z":"b003eab5.e1bff8","name":"Caution : This script will remove all your Node-Red Global Variables (From Default Store (You can change store in the function node))","info":"The Script loads global.json (File for all global variables) and process it, and removes all variables from Node-Red (Node-red have no builtin support to clear all global variables store (localfilesystem store))\n\nCreated by [email protected]\n","x":460,"y":680,"wires":[]}]

Flow Info

Created 3 years, 10 months ago
Rating:

Owner

Actions

Rate:

Node Types

Core
  • comment (x1)
  • debug (x1)
  • file in (x1)
  • function (x1)
  • inject (x1)

Tags

  • global
  • store
  • localfilesystem
  • variable
  • remove
  • delete
  • node-red
  • script
  • function
  • global.json
  • context
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option