• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Getting error using rss-parser

Scheduled Pinned Locked Moved Solved Troubleshooting
4 Posts 2 Posters 561 Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    sdillard
    last edited by Dec 22, 2021, 7:45 AM

    I’m creating a newer RSS feed module that updates regularly and rotates between different feeds. I think I am all good, but I am using rss-parser, and it doesn’t seem to be creating a new object when invoked.
    At the top of my node_helper.js file, I have

    var NodeHelper = require("node_helper");
    var RssParser = require("rss-parser");
    

    I’ve tried three ways to create a new parser object, but I always get parser.parse is undefined, which tells me that it isn’t creating the object, or the reference is invalid for some reason. I need a line to create the parser, like this:

    var parser = new RssParser();
    

    Here’s what I’ve tried:

    1. including this line below the require lines (see above),
    2. including in the socketNotificationReceived method, and
    3. creating a getter (see below)
    getParser: function() {
      if (this.parser === undefined) {
        this.parser = new RssParser();
      }
      return this.parser;
    }
    

    No luck! The documentation for rss-parser is clear and it works great when I run a local node script that just reads a feed.

    Help appreciated – I feel like I am missing something obvious…

    S 1 Reply Last reply Dec 22, 2021, 12:30 PM Reply Quote 0
    • S Away
      sdetweil @sdillard
      last edited by sdetweil Dec 22, 2021, 12:32 PM Dec 22, 2021, 12:30 PM

      @sdillard all variables defined inside the module register in node_helper need to be prefixed with this.

      and if u are using them after definition inside a callback or .then() handler u need to be careful as this. might point someplace other than the module context…

      for example a button press handler this. is pointing to the button object

      the problem can be addressed by saving this to another local variable and using that local variable as the prefix inside the callback

      let self=this
      axios.get(…).then(function(parms){ self. }

      or using the es6 arrow function, which retains the this context
      axios.get(…).then((parms)=>{ this. }

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      S 1 Reply Last reply Dec 22, 2021, 5:46 PM Reply Quote 0
      • S Offline
        sdillard @sdetweil
        last edited by Dec 22, 2021, 5:46 PM

        @sdetweil Thanks for the response. I figured it out (just needed a fresh look, I guess). It didn’t have to do with scoping or binding – I was using parser.parse() when it should be parser.parseURL().

        Just more for breadcrumbs for anyone reading this later, while it is true that it is important to scope a variable to self and do as you suggest, it is actually completely unnecessary in some cases and just leads to confusing code. If in my method I declare a require and then use that variable and no other method ever needs to use that variable, then scoping it to self just increases the size of the object unnecessarily since it can’t be garbage collected. And if I declare a require statement at the top of my module, I am creating a global variable, which can be dangerous and bad if I don’t understand what that means but is the right way if it is not an instance variable of the object.

        I don’t want to seem unappreciative – I do really appreciate your saying this as it made me requestion my code…

        S 1 Reply Last reply Dec 22, 2021, 7:11 PM Reply Quote 0
        • S Away
          sdetweil @sdillard
          last edited by Dec 22, 2021, 7:11 PM

          @sdillard glad u got it

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • 1 / 1
          1 / 1
          • First post
            2/4
            Last post
          Enjoying MagicMirror? Please consider a donation!
          MagicMirror created by Michael Teeuw.
          Forum managed by Sam, technical setup by Karsten.
          This forum is using NodeBB as its core | Contributors
          Contact | Privacy Policy