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.

    What is the difference between require() and getScripts()?

    Scheduled Pinned Locked Moved Development
    7 Posts 4 Posters 3.1k Views 3 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.
    • E Offline
      E3V3A
      last edited by E3V3A

      I’ve been trying to implement the jquery dependent package (Tabulator) on my mirror. What it does is, convert JSON data into a nice dynamic HTML table.

      In the working HTML version, I just the script tag, to include everything, but in a Node MMM, we can either use require("blablah") in the node_helper.js file, or use getScripts("blablah.js") in the MMM-MyModule.js file.

      1. What is the difference?
      2. When to use what?

      Right now I’m using the 2nd option, and it loads, but the table is never shown… I’m thinking I’m missing something.

      "Everything I do (here) is for free – altruism is the way!"
      MMM-FlightsAbove, MMM-Tabulator, MMM-Assistant (co-maintainer)

      N 1 Reply Last reply Reply Quote 0
      • N Offline
        ninjabreadman @E3V3A
        last edited by

        @E3V3A

        require() is for when you mean “I’m going to use this code somewhere else in this script I am writing right now” — i.e. somewhere on the server-side.

        getScripts() is for when you mean “my client-facing/browser code will need this loaded to perform some operation” — i.e. somewhere on the client-side.

        (As always, this is what I understand and hope someone will correct me if I’m wrong.)

        Problem with config or JavaScript? Copy/paste it into JSHint.
        Check out the detailed walkthroughs on install, config, modules, etc.

        E 1 Reply Last reply Reply Quote 3
        • E Offline
          E3V3A @ninjabreadman
          last edited by

          @ninjabreadman Aah! Finally. Thank you. That is the most sensible explanation I’ve seen.
          (If you’re a moderator, please mark this as closed/solved.)

          "Everything I do (here) is for free – altruism is the way!"
          MMM-FlightsAbove, MMM-Tabulator, MMM-Assistant (co-maintainer)

          1 Reply Last reply Reply Quote 0
          • cowboysdudeC Offline
            cowboysdude Module Developer
            last edited by cowboysdude

            Well you really shouldn’t mark this as closed or solved because I’m sure others will have questions too :)

            It’s a GREAT explanation… and it’s also a GREAT question!!! I’m sure others have wondered and I know people don’t usually ask for fear they’ll look ‘not smart’…but NO question is a dumb question!!

            The worst question in history? The one that never got asked! :)

            Mykle1M 1 Reply Last reply Reply Quote 0
            • Mykle1M Offline
              Mykle1 Project Sponsor Module Developer @cowboysdude
              last edited by

              @cowboysdude said in What is the difference between require() and getScripts()?:

              I know people don’t usually ask for fear they’ll look ‘not smart’

              I don’t have this problem. ;-)

              Create a working config
              How to add modules

              cowboysdudeC 1 Reply Last reply Reply Quote 0
              • cowboysdudeC Offline
                cowboysdude Module Developer @Mykle1
                last edited by

                @Mykle1 said in What is the difference between require() and getScripts()?:

                @cowboysdude said in What is the difference between require() and getScripts()?:

                I know people don’t usually ask for fear they’ll look ‘not smart’

                I don’t have this problem. ;-)

                Which one? Asking or not being smart LOL

                Mykle1M 1 Reply Last reply Reply Quote 1
                • Mykle1M Offline
                  Mykle1 Project Sponsor Module Developer @cowboysdude
                  last edited by

                  @cowboysdude

                  Both? ;-)

                  Create a working config
                  How to add modules

                  1 Reply Last reply Reply Quote 1
                  • 1 / 1
                  • First post
                    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