Read the statement by Michael Teeuw here.
Read local txt file from node_helper.js
-
@Aphamguin what is the problem? I don’t see anything obvious
also, see my Sample Module, which sends thru node_helper and gets response back which is shown.
https://github.com/sdetweil/SampleModule
if u are just showing text, you should use innerText, so the dom handler doesn’t have to examine your text only to find no html tags… (save cycles for other work)
-
@sdetweil it seems to break the module and MM. Nothing shows up on the screen when I run it.
Thanks for the sample module. It’s a really helpful template that I thought MM would have given us.
It’s a simple module, but I’m just implementing its functionality in phases. At the moment I just want it to read from a local txt file, parse it into an array, and then display a chunk of text by accessing that array. So yes I’m just showing text. What is innerText? Do I just do elem.innerText(“text”)
instead of elem.innerHTML(“text”)? -
@Aphamguin yes elem.innerText.
not sure what you mean by breaks mm…
if u email me the three files I will find what the problem is.
same user ID on gmail. rename the .js as .txt
-
@Aphamguin you did set a position for your module in config, right? else the output doesn’t get used
-
@Aphamguin the sample mm provides (hello world), uses the nunjuks template approach
-
@sdetweil I have emailed you the main js file, the helper, and the txt file, all as txt files. I hope you got it.
I did set a position, yes.
Where can I get the sample mm? What is the nunjuks template approach? -
@Aphamguin my sample module
https://github.com/sdetweil/SampleModuleI don’t have any links to nunjuks.
but basically you create a layout template with locations for variables, and then supply the data, and the template engine does that formatting
see the helloworld module in the defaults folderI am working on your module. the initial problem is the data filename has to have a path, else it will be in the MagicMirror folder.
but there is also an easier way to process your data.
in a couple hours I will get it back to you the same way
-
@sdetweil Ok I’ll play around with it then.
Wow great. Thanks a lot. I really appreciate it. -
@Aphamguin sent back
-
To conclude this issue, when reading from a local txt file with node_helper.js, you have to make sure the file name has a path. And then when parsing it, you can parse it easily by checking for carriage returns (\r) to see if if its a windows file. Here is a snippet of the solution:
this.rawText = fs.readFileSync(__dirname + '/localTxtFile.txt').toString() this.isWindows = (this.rawText.indexOf('\r') == -1) ? false:true this.variable= this.rawText.split(this.isWindows ? '\r\n\r\n' : '\n\n')