Navigation

    MagicMirror Forum

    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • Donate
    • Discord
    MagicMirror² v2.15.0 is available! For more information about this release, check out this topic.

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

    Development
    4
    7
    1894
    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
      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.

      N 1 Reply Last reply Reply Quote 0
      • N
        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.)

        E 1 Reply Last reply Reply Quote 3
        • E
          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.)

          1 Reply Last reply Reply Quote 0
          • cowboysdude
            cowboysdude Project Sponsor 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! 🙂

            Mykle1 1 Reply Last reply Reply Quote 0
            • Mykle1
              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. 😉

              cowboysdude 1 Reply Last reply Reply Quote 0
              • cowboysdude
                cowboysdude Project Sponsor 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

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

                  @cowboysdude

                  Both? 😉

                  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 Paul-Vincent Roll and Rodrigo Ramírez Norambuena.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy