• 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 module's URL from node_helper before socket connected

Scheduled Pinned Locked Moved Unsolved Feature Requests
8 Posts 4 Posters 885 Views 4 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.
  • K Offline
    karsten13 @MMRIZE
    last edited by May 4, 2022, 9:30 PM

    @MMRIZE

    Is there any convenient way to get the related/launched MM module’s basic URL from node_helper?

    AFAIS not really …

    You could iterate over the modules in the config.js doing something like this in the init() of your node_helper:

        const configFilename = path.resolve(
          global.configuration_file || `${global.root_path}/config/config.js`
        );
    
        let config;
        try {
          fs.accessSync(configFilename, fs.F_OK);
          const c = require(configFilename);
          config = Object.assign(c);
        } catch (e) {
          Log.error(name + ": Couldn't read config.js");
          return;
        }
    
        let modules = [];
    
        for (const module of config.modules) {
          if (
            !modules.includes(module.module) &&
            !module.disabled
          ) {
          console.dir(module.module);
          }
        }
    

    So you have the names and for knowing what are default modules you could use modules/default/defaultmodules.js

    S 1 Reply Last reply May 4, 2022, 9:59 PM Reply Quote 0
    • S Offline
      sdetweil @karsten13
      last edited by May 4, 2022, 9:59 PM

      @karsten13 wow!!!.. i didn’t think config was available to node_helper…

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      C 1 Reply Last reply May 5, 2022, 10:01 PM Reply Quote 0
      • C Offline
        cowboysdude Module Developer @sdetweil
        last edited by May 5, 2022, 10:01 PM

        @sdetweil Yes I send my config to node_helper in my weather module :)

        S 1 Reply Last reply May 5, 2022, 10:04 PM Reply Quote 0
        • S Offline
          sdetweil @cowboysdude
          last edited by May 5, 2022, 10:04 PM

          @cowboysdude said in Getting module's URL from node_helper before socket connected:

          Yes I send my config to node_helper in my weather module

          but that is not the topic

          without doing ANYTHING

          in the node_helper

          config points to the TOTAL config/config.js
          ALL modules and ALL (config.js) parms to ALL modules…

          this is NOT the merged with defaults view that you would send…

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          1 Reply Last reply Reply Quote 0
          • M Offline
            MMRIZE
            last edited by May 6, 2022, 6:34 AM

            Assuming URL with PATH might be an almost general solution, but Sometimes, People install modules in weird ways like using Symlink. (That way could have some benefit, anyway, this is out of issues) In that case, assuming is somehow picky.

            My purpose is to rewrite the Translator class to use in Module and node_helper together with one common class. (So that is the reason why pre-connection is needed.)To access translations in both layers, there could be many ways to achieve. However, if the exact URL could be obtained in the background layer, it would be easier and simpler and with the least dependency. (To work on browser and on nodejs layer together)

            Of course, there could be many alternative approaches. I’m just curious if there could be a better way.

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