Node-RED系列(七):Node-RED存储节点的使用
上一期我们讲到了Node-RED中解析parser分类节点的使用,利用解析节点我们可以对csv,html,json,xml,yaml文件进行解析。获取一些格式化内容。
本篇文章我来给大家讲一下Node-RED中存储file分类下的节点,该分类下有4个节点,
- file 将msg.payload写入文件,添加到末尾或替换现有内容。或者,它也可以删除文件。
- file in 以字符串或二进制缓冲区的形式读取文件的内容。
- watch 监视目录或文件中的更改。
- tail 监听被一个文件被添加的内容
file
该节点是将msg.payload写入文件,添加到末尾或替换现有内容。或者,它也可以删除文件。
输入 filename, 也可以配置,如果没有该目录,则自动创建。写入完成后,输入消息将发送到输出端口
每个消息的有效荷载将添加到文件的末尾,可以选择在每个消息之间添加一个换行符(\n)。
如果使用msg.filename,则每次写入后文件都会关闭。为了获得最佳体验,请使用固定的文件名。
可以将其配置为覆盖整个文件,而不是在文件后添加段落。例如,在将二进制数据写入文件(例如图像)时,应使用此选项,并且应禁用添加换行符的选项。
可以从编码列表中指定写入文件的数据的编码。
您可以将此节点配置为删除文件
file in
该节点能以字符串或二进制缓冲区的形式读取文件的内容。
输入 filename 如果未在节点配置中设置,该属性可以选择要读取的文件名。
输入
payload 文件的内容可以是字符串,也可以是二进制的buffer。
filename 如果未在节点配置中设置,该属性可以选择要读取的文件名。
watch
改节点用于监视目录或文件中的更改。
您可以输入用逗号分隔的目录和/或文件的列表。您需要在所有带有空格的地方加上引号“...”。
在Windows上,必须在任何目录名称中使用双反斜杠\。
实际更改的文件的完整文件名将放入msg.payload和msg.filename中,而监视列表的字符串化版本将在msg.topic中返回。
msg.file仅包含已更改文件的短文件名。msg.type更改了事物的类型,通常是file或directory,而msg.size保留了文件的大小(以字节为单位)。
当然,在Linux中,everything也是一个文件,因此可以监视
注意:该目录或文件必须存在才能被监视。如果文件或目录被删除,即使重新创建它也可能不再被监视。
tail
监听已配置文件中,被添加的内容。
在Windows上你需要根本文件的写入和更新注册。
输出的是UTF-8的字符,或者二进制文件流
完整的流配置
[
{
"id": "c9eae563.294d18",
"type": "tab",
"label": "流程 3",
"disabled": false,
"info": ""
},
{
"id": "738ced86.140b84",
"type": "file",
"z": "c9eae563.294d18",
"name": "追加到12.txt",
"filename": "12.txt",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"encoding": "none",
"x": 490,
"y": 260,
"wires": [
[
"921006b.457b4f8"
]
]
},
{
"id": "8dee2a6f.831118",
"type": "inject",
"z": "c9eae563.294d18",
"name": "",
"props": [
{
"p": "payload"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "我是被追加的",
"payloadType": "str",
"x": 190,
"y": 260,
"wires": [
[
"738ced86.140b84",
"3576d67e.f638fa"
]
]
},
{
"id": "921006b.457b4f8",
"type": "debug",
"z": "c9eae563.294d18",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 260,
"wires": []
},
{
"id": "3576d67e.f638fa",
"type": "file in",
"z": "c9eae563.294d18",
"name": "读取12.txt",
"filename": "12.txt",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"x": 500,
"y": 400,
"wires": [
[
"921006b.457b4f8"
]
]
},
{
"id": "b231a4b7.143ea8",
"type": "watch",
"z": "c9eae563.294d18",
"name": "监听12.txt文件",
"files": "12.txt",
"recursive": "",
"x": 500,
"y": 620,
"wires": [
[
"7fba4883.304338"
]
]
},
{
"id": "7fba4883.304338",
"type": "debug",
"z": "c9eae563.294d18",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 620,
"wires": []
},
{
"id": "fdf417e5.6c4db8",
"type": "tail",
"z": "c9eae563.294d18",
"name": "监听并获取12.txt内容",
"filetype": "text",
"split": "[\\r]{0,1}\\n",
"filename": "12.txt",
"inputs": 0,
"x": 500,
"y": 700,
"wires": [
[
"d8ada19c.f13ec"
]
]
},
{
"id": "d8ada19c.f13ec",
"type": "debug",
"z": "c9eae563.294d18",
"name": "",
"active": true,
"tosidebar": true,
"console": true,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 770,
"y": 700,
"wires": []
}
]
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
- 129
- 130
- 131
- 132
- 133
- 134
- 135
- 136
- 137
- 138
- 139
- 140
- 141
- 142
- 143
- 144
- 145
- 146
- 147
- 148
- 149
- 150
- 151
- 152
- 153
- 154
- 分享
- 举报

-
浏览量:27262次2021-01-25 17:57:21
-
浏览量:33251次2021-02-07 17:30:47
-
浏览量:16598次2021-02-08 15:04:50
-
浏览量:14532次2021-01-14 18:10:48
-
浏览量:18841次2021-01-06 19:08:06
-
浏览量:23439次2021-01-04 10:25:54
-
浏览量:30771次2021-01-05 15:11:35
-
浏览量:35576次2021-02-08 11:42:45
-
浏览量:23397次2021-03-15 15:40:13
-
浏览量:20631次2021-02-20 17:22:26
-
浏览量:26090次2020-12-31 14:58:17
-
2021-04-12 20:00:58
-
浏览量:82065次2020-12-28 16:39:38
-
浏览量:14299次2021-03-24 16:14:07
-
浏览量:15455次2021-07-29 17:28:08
-
浏览量:13251次2021-02-20 17:52:54
-
浏览量:725次2021-01-14 18:30:53
-
浏览量:14564次2021-03-16 10:46:12
-
浏览量:11711次2021-05-11 19:30:21
-
广告/SPAM
-
恶意灌水
-
违规内容
-
文不对题
-
重复发帖

这把我C






举报类型
- 内容涉黄/赌/毒
- 内容侵权/抄袭
- 政治相关
- 涉嫌广告
- 侮辱谩骂
- 其他
详细说明