Hello,
I have a very simple module that executes a linux “cat” command on a file every N seconds.
It works as expected except the line breaks in the file are ignored. All lines are displayed as 1 single line.
This is how I call the cat command inside node_helper.js:
var NodeHelper = require(‘node_helper’);
const exec = require(‘child_process’).exec;
module.exports = NodeHelper.create({
readfile: function () {
exec("cat /path/to/file/out.txt", (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
this.sendSocketNotification('UPDATE', stdout);
});
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'TICK') {
this.readfile();
}
},
});
Inside the module class, this is how I handle the update coming from socketNotificationReceived:
socketNotificationReceived: function(notification, payload) {
if (notification === 'UPDATE') {
this.config.text = payload;
this.updateDom()
}
},
The reason I took this approach is I have absolutely no JS experience whatsoever, so I’m preparing the text file using a bash script and then use my MMM to display the result. (I moved the processing outside JS domain)
Is it possible to use “cat” and display multiline?
Or should I use a completely different approach e.g. reading the file inside JS line by line and displaying the result. If this is the correct approach then please point me to some examples.
Thanks in advance