<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Module development node_helper.js config loading]]></title><description><![CDATA[<p dir="auto">Hi folks,<br />
I’m writing a module at the moment and have most of it covered, except loading in my config, some functions seem able to access this.config and others don’t<br />
So first, I’m loading in config like this in node_helper.js:</p>
<pre><code>        socketNotificationReceived: function(notification, payload) {
                switch(notification) {
                        case "INIT":
                                this.initConfigs(payload);
                        break

initConfigs: function(config) {
                this.config = config;
                this.sendSocketNotification('INIT-DONE');
                this.init = true;
        },

</code></pre>
<p dir="auto">And I send that from the main.js by doing:</p>
<pre><code>this.sendSocketNotification("INIT", this.config);
</code></pre>
<p dir="auto">Which works, so in most functions I can then call<br />
this.config.MyVariable and output it.<br />
However in some functions if I try and call the same variable, I get an exception error:</p>
<pre><code>[11:17:32.435] [ERROR]  TypeError: Cannot read property 'verbose' of undefined
</code></pre>
<p dir="auto">So it seems inconsistent.<br />
How would I define this.config in node_helper.js to be a global variable, should I change reference, move it to a var at the top of node_helpher.js and set it there rather than using the internal this. functions for variable definitions?<br />
Thanks in advance.</p>
]]></description><link>https://forum.magicmirror.builders/topic/12418/module-development-node_helper-js-config-loading</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 18:10:56 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/12418.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 26 Mar 2020 11:33:21 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Module development node_helper.js config loading on Thu, 26 Mar 2020 13:34:20 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andyb2000" aria-label="Profile: andyb2000">@<bdi>andyb2000</bdi></a> you did perfect!!</p>
<p dir="auto">glad u got it working</p>
<p dir="auto">u didn’t NEED to pass it, as this.my_control() worked, the ‘this’ pointer  is correct inside the function…</p>
]]></description><link>https://forum.magicmirror.builders/post/71182</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71182</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 26 Mar 2020 13:34:20 GMT</pubDate></item><item><title><![CDATA[Reply to Module development node_helper.js config loading on Thu, 26 Mar 2020 13:31:40 GMT]]></title><description><![CDATA[<p dir="auto">Aha, thank you that’s set me on the right path!</p>
<p dir="auto">It was indeed when calling it from another service, in this case a setInterval event was calling it which got it confused. Thanks for the suggestion on the newer callback, I solved it in the slightly older low-tech way:</p>
<pre><code>this.timer_socketforever = setInterval(()=&gt;{
                        this.my_control(this.config)
                        }, 30000);

</code></pre>
<p dir="auto">So that the config info was passed as a parameter.<br />
Problem solved, thank you!</p>
]]></description><link>https://forum.magicmirror.builders/post/71181</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71181</guid><dc:creator><![CDATA[andyb2000]]></dc:creator><pubDate>Thu, 26 Mar 2020 13:31:40 GMT</pubDate></item><item><title><![CDATA[Reply to Module development node_helper.js config loading on Thu, 26 Mar 2020 11:40:07 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/andyb2000" aria-label="Profile: andyb2000">@<bdi>andyb2000</bdi></a> the problem is that some functions are in callbacks from library services, and ‘this’ at the time is relative to the LIBRARY…</p>
<p dir="auto">if you do var self=this at the beginning of the surrounding function, and use self. instead,   javascript will figure it out…</p>
<p dir="auto">or, use the newer callback definition (arrow functions)    ()=&gt;{}<br />
which maintain the outer context , where function(){}  does not<br />
the arrow function operator requires a newer level of javascript then when MM was originally written, but has been available since node 6 I think…(we are using node 10)</p>
]]></description><link>https://forum.magicmirror.builders/post/71173</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/71173</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Thu, 26 Mar 2020 11:40:07 GMT</pubDate></item></channel></rss>