Get and show timestamp of last flow saving

Perhaps a little bit unusal, but I want to show the timestamp of last saving in my flow. Currently I have a comment field like this:

grafik

But it's not done automatically, so I often forget to actualize it. The version changes not so often. That's no problem. But it would be nice to show the timestamp automatically after saving (export and download).

Is there any way?

1 Like

The flows are kept in a json file so all you need to do is to find the last update timestamp on that file. There are filing system nodes that will do that.

Alternatively, you may be able to use a watch node to watch for changes to the file. However, if you are doing that, make sure you put a delay on the output do help debounce it because file updates may happen multiple times for a single "save" operation (I've not tested it with the flow json file).

and perhaps doing a shell script to parse and modify some part of the flow.js file (e.g. the name of a node or the name of a flow TAB) ?

In a normal development environment the same is always the same. But in Node-Red, where I us a browser for development, I make a download, when I do a save/export. In this case I get always a new file in the download directory. So I can't find the last timestamp of file!?

The other question is, if it is possible to integrate it in the comment field? How to do it? Or is there another node to display dynamic information in the flow.

I did a quick test and the result is promising. I could change the label of the remark node with a script in Node-RED. This may be a starting point to get you going. Just be careful to not play with sensitive flows. It is advisable to use a testing environment to not risk your flows.

r-1

[{"id":"c250b46e.0b6d88","type":"tab","label":"AAA","disabled":false,"info":""},{"id":"5e65cebb.b05e6","type":"comment","z":"c250b46e.0b6d88","name":"AAA 2021-03-14T19:05:27.190Z","info":"AAA","x":290,"y":120,"wires":[]},{"id":"fcc286c1.f2a1a8","type":"inject","z":"c250b46e.0b6d88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":220,"y":200,"wires":[["ce2ee89b.6ff4d8"]]},{"id":"c5a64ff.d9b53b","type":"function","z":"c250b46e.0b6d88","name":"","func":"let pay = msg.payload;\n\nlet row = pay.findIndex(element => element.info === \"AAA\");\n\npay[row].name = \"AAA \" + new Date().toISOString();\n\nmsg.payload = pay;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":200,"wires":[["8660bd16.6ebe4"]]},{"id":"ce2ee89b.6ff4d8","type":"file in","z":"c250b46e.0b6d88","name":"Read flow.json","filename":"C:/Users/OCM/.node-red/projects/TESTE-DELETE/flow.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":400,"y":200,"wires":[["6249bd41.185694"]]},{"id":"6249bd41.185694","type":"json","z":"c250b46e.0b6d88","name":"","property":"payload","action":"obj","pretty":false,"x":550,"y":200,"wires":[["c5a64ff.d9b53b"]]},{"id":"6ed38985.fa4158","type":"file","z":"c250b46e.0b6d88","name":"Save flow.json","filename":"C:/Users/OCM/.node-red/projects/TESTE-DELETE/flow.json","appendNewline":true,"createDir":false,"overwriteFile":"true","encoding":"none","x":660,"y":280,"wires":[[]]},{"id":"8660bd16.6ebe4","type":"json","z":"c250b46e.0b6d88","name":"","property":"payload","action":"str","pretty":false,"x":430,"y":280,"wires":[["6ed38985.fa4158"]]}]

I wouldn't actually recommend that. I think there is too much to go wrong.

Rather, I would update a global variable and have a small flow to read the variable and output to a debug node showing just the status message.

Best to avoid trying to amend your flows json file via Node-RED if possible I think.

Or even write a tiny contrib node.

I concur with you. I just wanted to show one possible way that is by modifying the flow file but I think there is too much risk involved.

Thanks for comments and example. For this application it's perhaps not really save, as you write, but it's an good example for me how basically I can do things llike this. So it was good for learning :-).

In the meantime I found some discussion of storing the flow in GitHub. I'll now dig deeper and perhaps this is a workaround to have flows with (indirect) timestamp. And this than will perhaps be a good way of storing and retrieving code like in other programming languages.

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