Hi,
I am struggling with a file that I am trying to watch for changes. I use the fs.watch, and listening on the 'change' event. It works fine, but when I hit the "Deploy" button in node-red, it opens another watcher, if I hit "Deploy" again, a third watcher appear. (Bonus info - i am running Linux). It seems it doesnt close the previously watchers. Do you have any suggestions?
Here is my .js code:
fs.watch(doPath, (eventType, filename) => {
var msg = {payload: ""};
if(eventType === 'change') {
fs.readFile(doPath, 'utf8', (err, data) => {
if (err) throw err;
if(data[0] == 1) {
msg.payload = true;
node.send(msg);
node.status({fill:"green",shape:"dot",text:"digital-outputs.status.on"});
}
else if (data[0] == 0) {
node.status({fill:"red",shape:"dot",text:"digital-outputs.status.off"});
msg.payload = false;
node.send(msg);
}
});
}
});