Reputation: 67
I want to save incoming json strings (HTTP in) to a file after processing is done for logging purposes.
To save the file, I use the file node (out).
The node is configured to append to file and also to create directory if not exist.
The node always throw an exception TypeError: this is not a typed array
.
Stack Trace:
"TypeError: this is not a typed array.↵ at Function.from (native)↵ at FileNode. (/usr/local/lib/node_modules/node-red/nodes/core/storage/50-file.js:67:39)↵ at emitOne (events.js:77:13)↵ at FileNode.emit (events.js:169:7)↵ at FileNode.Node.receive (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:215:14)↵ at FunctionNode.Node.send (/usr/local/lib/node_modules/node-red/red/runtime/nodes/Node.js:202:14)↵ at sendResults (/usr/local/lib/node_modules/node-red/nodes/core/core/80-function.js:52:18)↵ at FunctionNode. (/usr/local/lib/node_modules/node-red/nodes/core/core/80-function.js:205:21)↵ at emitOne (events.js:77:13)↵ at FunctionNode.emit (events.js:169:7)"
Could someone please explain what I'm missing? The file I want to create does not exist. Just before the file node, I set msg.filename to create unique filenames (timestamp). It only creates the folder, if missing, but never create a file.
I also tried to set a simple string instead of json object as payload, but this also doesn't work.
I found some hints that I should upgrade to lastest node.js and node-red. Currently I'm using node-red V 0.18.4
and node.js V9.9.0
Thanks for your help.
Here is my current flow
[{"id":"e2d9bca5.4c3f78","type":"http in","z":"4961d970.3e0778","name":"send_data","url":"/incomingData","method":"post","upload":false,"swaggerDoc":"","x":110,"y":120,"wires":[["5400ed9e.a8353c"]]},{"id":"b0ad409a.8e9a1","type":"http response","z":"4961d970.3e0778","name":"HTTP Error Resonse","statusCode":"400","headers":{},"x":720,"y":380,"wires":[]},{"id":"b6620bad.3c7848","type":"file","z":"4961d970.3e0778","name":"error file","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"true","x":960,"y":400,"wires":[]},{"id":"16cac0d3.070297","type":"file","z":"4961d970.3e0778","name":"data file","filename":"","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1060,"y":180,"wires":[]},{"id":"595e3863.fe83e","type":"http response","z":"4961d970.3e0778","name":"http success","statusCode":"200","headers":{},"x":850,"y":220,"wires":[]},{"id":"2cfbe34e.53a42c","type":"function","z":"4961d970.3e0778","name":"set filename for data","func":"var now = Date.now();\nvar filename = '/home/nodered/data/data_' + now + '.txt';\nmsg.filename = filename;\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":180,"wires":[["16cac0d3.070297"]]},{"id":"af847029.5c8968","type":"function","z":"4961d970.3e0778","name":"set filename for error","func":"var now = Date.now();\nvar filename = '/home/nodered/data/error_' + now + '.txt';\nmsg.filename = filename;\n\nreturn msg;","outputs":1,"noerr":0,"x":720,"y":420,"wires":[["b6620bad.3c7848"]]},{"id":"eb0f3370.4e922","type":"catch","z":"4961d970.3e0778","name":"catch JSON parse errors","scope":["5400ed9e.a8353c"],"x":410,"y":180,"wires":[["4bb56ef4.7d1f2","b0ad409a.8e9a1","af847029.5c8968"]]},{"id":"4bb56ef4.7d1f2","type":"debug","z":"4961d970.3e0778","name":"Show error message in debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":750,"y":320,"wires":[]},{"id":"5400ed9e.a8353c","type":"json-schema-validator","z":"4961d970.3e0778","name":"check json string","func":"{\n \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n \"id\": \"http://mynet.com/schemas/user.json#\",\n \"title\": \"Data\",\n \"description\": \"Data\",\n \"type\": \"object\",\n \"required\":[\"serialnr\", \"mappingcode\", \"data\"],\n \"properties\": {\n \"serialnr\": {\n \"description\": \"Serial number of machine\",\n \"type\": [\"string\"],\n \"pattern\": \"^[1-9][0-9]*$\",\n \"minLength\": 13,\n \"maxLength\": 13\n },\n \"mappingcode\": { \"type\": \"integer\", \"maximum\": 99999},\n \"yyyymmdd\": { \"type\": \"integer\", \"maximum\":20301231, \"minimum\":20150101 },\n \"data\": {\n \"type\": \"object\",\n \"additionalProperties\": { \"type\": \"string\" },\n \"maxProperties\": 200,\n \"required\": [\"data1\",\"data2\"]\n }\n \n }\n}","x":340,"y":120,"wires":[["2cfbe34e.53a42c","595e3863.fe83e"]]},{"id":"540ca799.905db8","type":"catch","z":"4961d970.3e0778","name":"","scope":["16cac0d3.070297","b6620bad.3c7848"],"x":1000,"y":480,"wires":[["83f0ce5e.11b378"]]},{"id":"83f0ce5e.11b378","type":"debug","z":"4961d970.3e0778","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":1150,"y":480,"wires":[]}]
Upvotes: 0
Views: 1510
Reputation: 67
Thank you Steve,
after downgrading fom 9.9.0 back to 8.10.0 I'm able to create files.
Upvotes: 0