• 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.

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

Scheduled Pinned Locked Moved Development
7 Posts 4 Posters 3.0k 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 Feb 19, 2018, 10:14 PM Feb 19, 2018, 10:12 PM

    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 Feb 20, 2018, 12:59 AM Reply Quote 0
    • N Offline
      ninjabreadman @E3V3A
      last edited by Feb 20, 2018, 12:59 AM

      @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 Feb 20, 2018, 10:30 AM Reply Quote 3
      • E Offline
        E3V3A @ninjabreadman
        last edited by Feb 20, 2018, 10:30 AM

        @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
        • C Offline
          cowboysdude Module Developer
          last edited by cowboysdude Feb 20, 2018, 11:28 AM Feb 20, 2018, 11:27 AM

          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! :)

          M 1 Reply Last reply Feb 20, 2018, 1:34 PM Reply Quote 0
          • M Offline
            Mykle1 Project Sponsor Module Developer @cowboysdude
            last edited by Feb 20, 2018, 1:34 PM

            @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

            C 1 Reply Last reply Feb 21, 2018, 2:19 AM Reply Quote 0
            • C Offline
              cowboysdude Module Developer @Mykle1
              last edited by Feb 21, 2018, 2:19 AM

              @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

              M 1 Reply Last reply Feb 21, 2018, 2:24 AM Reply Quote 1
              • M Offline
                Mykle1 Project Sponsor Module Developer @cowboysdude
                last edited by Feb 21, 2018, 2:24 AM

                @cowboysdude

                Both? ;-)

                Create a working config
                How to add modules

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