Read the statement by Michael Teeuw here.
Getting module's URL from node_helper before socket connected
-
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 theinit()
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
-
@karsten13 wow!!!.. i didn’t think config was available to node_helper…
-
@sdetweil Yes I send my config to node_helper in my weather module :)
-
@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…
-
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.