I'm experimenting trying to learn how to create nodes with installing them locally with npm install
on the package.json
file.
For learning purposes & experimentation, I have very generic node called msg-recycler
where at the moment I am just feeding some string data into it attempting to validate the data and return Boolean True or False on the node output for the message.topic.
This is the data inside the inject node selected as JSON that I am trying to validate key values only:
{"VAV1": "read 12345:2 analogInput 2",
"VAV2": "read 12345:2 analogInput 1",
"VAV3": "read 12345:2 analogInput 1",
"VAV4": "read 12345:2 analogInput 2",
"VAV5": "read 12345:2 analogInput 1",
"VAV6": "read 12345:2 analogInput 2",
"VAV7": "read 12345:2 analogInput 1",
"VAV8": "read 12345:2 analogInput 1",
"VAV9": "read 12345:2 analogInput 2",
"VAV10": "read 12345:2 analogInput 1"}
the javascript file that installed with npm install
is this:
module.exports = function (RED) {
"use strict";
function msgRecycler(config) {
RED.nodes.createNode(this, config);
var node = this;
this.on('input', function (msg) {
const validateRequestType = type =>
['read', 'write', 'release'].includes(type);
const validatePointType = type =>
['analogInput', 'analogValue', 'binaryValue', 'binaryInput'].includes(type);
// "read 12345:11 analogInput 1"
const validate = str => {
const [requestType, deviceAddress, pointType, pointAddress] = str.split(' ');
return validateRequestType(requestType) && validatePointType(pointType);
}
const valid = Object.values(msg).every(validate);
msg.payload = valid; //Boolean
node.send(msg);
});
}
RED.nodes.registerType("msgrecycling", msgRecycler);
};
Basically its validating the word in the string read
(requestType) and analogInput
(pointType) in the string "read 12345:2 analogInput 1" in the validate
function, hopefully that makes sense. I am trying return Boolean in the Node msg.payload = valid; //Boolean
In the debug I get this returned, circular dependancy issue. Would anyone have any tips to try?
msg.payload : Object
object
_msgid: "342fbccf54e4904f"
payload: "[Circular ~]"
topic: ""
Any tips help not a lot of wisdom here...