Node-RED Flow Examples
How to write files with atomicity?
Copy this flow and take it to Node-Red.
[
{
"id": "0b965bc0612aee1f",
"type": "tab",
"label": "Flow 1",
"disabled": false,
"info": "",
"env": []
},
{
"id": "60ebcedb3c9f8e01",
"type": "inject",
"z": "0b965bc0612aee1f",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payloadType": "date",
"x": 390,
"y": 160,
"wires": [
[
"cc67d46255be457f"
]
]
},
{
"id": "cc67d46255be457f",
"type": "function",
"z": "0b965bc0612aee1f",
"name": "",
"func": "msg.payload =\n{\n \"var1\": \"value1\",\n \"var2\": \"value2\",\n \"var3\": \"value3\",\n \"var4\": \"value4\",\n \"var5\": 123,\n \"var6\": \"value6\",\n \"var7\": \"value7\",\n \"var8\": \"value8\",\n \"var9\": \"value9\",\n \"var10\": \"value10\",\n}\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 160,
"wires": [
[
"d94a18ce123f5ab6"
]
]
},
{
"id": "5514cd38b69eb369",
"type": "exec",
"z": "0b965bc0612aee1f",
"command": "mv /home/root/vars.db.temp /home/root/vars.db; sync",
"addpay": "",
"append": "",
"useSpawn": "false",
"timer": "",
"winHide": false,
"oldrc": false,
"name": "",
"x": 1120,
"y": 160,
"wires": [
[],
[],
[]
]
},
{
"id": "d94a18ce123f5ab6",
"type": "file",
"z": "0b965bc0612aee1f",
"name": "",
"filename": "/home/root/vars.db.temp",
"filenameType": "str",
"appendNewline": true,
"createDir": true,
"overwriteFile": "true",
"encoding": "none",
"x": 770,
"y": 160,
"wires": [
[
"5514cd38b69eb369"
]
]
}
]