Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    1. Home
    2. Aphamguin
    A
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 0
    • Groups 0

    Aphamguin

    @Aphamguin

    0
    Reputation
    3
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Aphamguin Follow

    Latest posts made by Aphamguin

    • RE: Read local txt file from node_helper.js

      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')
      
      posted in Troubleshooting
      A
      Aphamguin
    • RE: Read local txt file from node_helper.js

      @sdetweil Ok I’ll play around with it then.
      Wow great. Thanks a lot. I really appreciate it.

      posted in Troubleshooting
      A
      Aphamguin
    • RE: Read local txt file from node_helper.js

      @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?

      posted in Troubleshooting
      A
      Aphamguin
    • RE: Read local txt file from node_helper.js

      @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”)?

      posted in Troubleshooting
      A
      Aphamguin
    • Read local txt file from node_helper.js

      I am currently creating my own MM module, but am still relatively new to the platform so I used this tutorial to help me get started: https://forum.magicmirror.builders/topic/8534/head-first-developing-mm-module-for-extreme-beginners
      It mentions that the node_helper.js is able to read from local files, but I’m having trouble getting it to work.

      Here’s what my node_helper.js looks like so far:

      var NodeHelper = require("node_helper")
      var fs = require('fs')
      
      module.exports = NodeHelper.create({
      	start: function() {
      		this.rawText = fs.readFileSync('YourTrueHome.txt').toString()
      		this.readIn = this.rawText.split('\r')  //array of book line by line
      		this.text = this.readIn[1]
      	},
      socketNotificationReceived: function(notification, payload) {
      	switch(notification) {
      		case "DO_YOUR_JOB":
      			this.sendSocketNotification("I_DID", this.text)
      			break
      		}
      	},
      })
      

      And then in the main js file, the socket notification receiver simply reads:

      socketNotificationReceived: function(notification, payload) {
      		switch(notification){
      			case "I_DID":
      				let elem = document.getElementById("COUNT")
      				elem.innerHTML = "Count: " + payload
      				break
      		}
      	},
      

      There is a COUNT element correctly defined in getDom: function() already.

      posted in Troubleshooting
      A
      Aphamguin