As the number of outputs is stored in the flow_xx.json
, you could read it from the file:
function get_outputs(node_name, callback) {
var fs = global.get('fs');
const flow_file = '/home/pi/.node-red/flows_rpi4.json';
fs.readFile(flow_file, function (err, data) {
if (err) {
node.warn(err);
} else {
var nodes = JSON.parse(data);
Object.keys(nodes).forEach(function(key) {
if (nodes[key].name === node_name) {
callback(nodes[key].outputs);
}
});
}
});
}
get_outputs('fun_name', function(outputs) {
msg.payload = outputs;
node.send(msg);
});
Replace fun_name
by the name of you function and flow_rpi4.json
by your flow name.
Note: fs has to be defined in the settings.js
[{"id":"2d3bbb37.d24584","type":"function","z":"ac4aa9f6.c24288","name":"fun_name","func":"function get_outputs(node_name, callback) {\n var fs = global.get('fs');\n const flow_file = '/home/pi/.node-red/flows_rpi4.json';\n \n fs.readFile(flow_file, function (err, data) {\n if (err) {\n node.warn(err);\n } else {\n var nodes = JSON.parse(data);\n Object.keys(nodes).forEach(function(key) {\n if (nodes[key].name === node_name) {\n callback(nodes[key].outputs);\n }\n });\n }\n });\n}\n\nget_outputs('fun_name', function(outputs) {\n msg.payload = outputs;\n node.send(msg);\n});\n","outputs":2,"noerr":0,"x":360,"y":1600,"wires":[["a2137d2d.e68aa"],[]]},{"id":"a2137d2d.e68aa","type":"debug","z":"ac4aa9f6.c24288","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":550,"y":1600,"wires":[]},{"id":"a037c85e.9e5c28","type":"inject","z":"ac4aa9f6.c24288","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":1600,"wires":[["2d3bbb37.d24584"]]}]