<?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[Config modules from external file (JSON)]]></title><description><![CDATA[<p dir="auto">Hi.</p>
<p dir="auto">I want to define my modules [] in a separate JSON file and then have config.js read from that file and populate it.</p>
<p dir="auto">Is it possible? something like this</p>
<pre><code>var config = 
{
  address: "0.0.0.0",
  electronOptions: {},
  ipWhitelist: [],
  language: "pt",
  modules: loadJSON("configuration.json"),
  paths: {
    modules: "modules",
    vendor: "vendor"
  },
  useHttps: false,
  httpsPrivateKey: "",
  httpsCertificate: ""
};

function loadJSON(filePath){
   try {
        var fs = require('fs');
        var path = require('path');
        var filename = path.resolve(__dirname, filePath);
        var jsonFile = JSON.parse(fs.readFileSync(filename));
        return jsonFile;
      } catch (e) {
         console.error(e);
          return [];
      }  
}

</code></pre>
<p dir="auto">Thank you</p>
]]></description><link>https://forum.magicmirror.builders/topic/14510/config-modules-from-external-file-json</link><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 01:59:12 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/14510.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 25 Jan 2021 23:37:26 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Config modules from external file (JSON) on Tue, 05 Jul 2022 21:12:13 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/sdetweil" aria-label="Profile: sdetweil">@<bdi>sdetweil</bdi></a> thanks for the tip. Unfortunately, I couldn’t find a good js/python script example for that. For a while, I ended up creating a simple batch script to append multiple json config files for each module in between the config header and footer. In case you remember a place were I can find a thread for that discussion, please let me know.</p>
]]></description><link>https://forum.magicmirror.builders/post/102670</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/102670</guid><dc:creator><![CDATA[tatianobusatto]]></dc:creator><pubDate>Tue, 05 Jul 2022 21:12:13 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Tue, 05 Jul 2022 10:14:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/tatianobusatto" aria-label="Profile: tatianobusatto">@<bdi>tatianobusatto</bdi></a> others have written js/python code that takes their settings ( file, database, web service) and applied to a model config.js.  (all their modules with fake strings for keys, etc)<br />
and call that js/python just before launching mm</p>
<p dir="auto">in installers/mm.sh</p>
]]></description><link>https://forum.magicmirror.builders/post/102652</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/102652</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 05 Jul 2022 10:14:44 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Tue, 05 Jul 2022 05:28:52 GMT]]></title><description><![CDATA[<p dir="auto">Hi, I’m trying something similar. Have you managed to solve your issue using this fuction loadJSON? If not, did you find any solution to update config.js “dinamicaly”?</p>
]]></description><link>https://forum.magicmirror.builders/post/102650</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/102650</guid><dc:creator><![CDATA[tatianobusatto]]></dc:creator><pubDate>Tue, 05 Jul 2022 05:28:52 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 18:59:56 GMT]]></title><description><![CDATA[<p dir="auto">It could probably be that the XmlHttpRequest is async and the page is already loaded when the request has finished executing.</p>
]]></description><link>https://forum.magicmirror.builders/post/87894</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87894</guid><dc:creator><![CDATA[telmini]]></dc:creator><pubDate>Wed, 27 Jan 2021 18:59:56 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:33:34 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> so the returncode is right  but its not fatal in mm view.</p>
]]></description><link>https://forum.magicmirror.builders/post/87891</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87891</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:33:34 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:32:39 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> because its looking for the (optional) node_helper.js of a module.<br />
this one, currentweather doesnt use one</p>
]]></description><link>https://forum.magicmirror.builders/post/87890</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87890</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:32:39 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:26:43 GMT]]></title><description><![CDATA[<p dir="auto">Sorry, this is the output.</p>
<pre><code>&gt; magicmirror@2.11.0 start /home/pi/MagicMirror
&gt; DISPLAY="${DISPLAY:=:0}" ./node_modules/.bin/electron js/electron.js

[2021-01-27 16:55:09.858] [LOG]    Starting MagicMirror: v2.11.0
[2021-01-27 16:55:09.878] [LOG]    Loading config ...
[2021-01-27 16:55:09.892] [LOG]    Loading module helpers ...
[2021-01-27 16:55:09.896] [LOG]    Error: ENOENT: no such file or directory, access '/home/pi/MagicMirror/js/../modules/default/currentweather/node_helper.js'
    at Object.accessSync (fs.js:202:3)
    at Object.fs.accessSync (electron/js2c/asar.js:491:38)
    at Object.fs.accessSync (electron/js2c/asar.js:491:38)
    at loadModule (/home/pi/MagicMirror/js/app.js:124:7)
    at loadNextModule (/home/pi/MagicMirror/js/app.js:166:5)
    at loadModules (/home/pi/MagicMirror/js/app.js:177:3)
    at /home/pi/MagicMirror/js/app.js:223:4
    at loadConfig (/home/pi/MagicMirror/js/app.js:72:4)
    at App.start (/home/pi/MagicMirror/js/app.js:211:3)
    at Object.&lt;anonymous&gt; (/home/pi/MagicMirror/js/electron.js:115:7) {
  errno: -2,
  syscall: 'access',
  code: 'ENOENT',
  path: '/home/pi/MagicMirror/js/../modules/default/currentweather/node_helper.js'
}
[2021-01-27 16:55:09.924] [LOG]    No helper found for module: currentweather.
[2021-01-27 16:55:09.926] [LOG]    All module helpers loaded.
[2021-01-27 16:55:10.246] [LOG]    Starting server on port 8080 ... 
[2021-01-27 16:55:10.256] [INFO]   You're using a full whitelist configuration to allow for all IPs
[2021-01-27 16:55:10.268] [LOG]    Server started ...
[2021-01-27 16:55:10.268] [LOG]    Sockets connected &amp; modules started ...
[2021-01-27 16:55:10.428] [LOG]    Launching application.
^[$

</code></pre>
<p dir="auto">I don’t understand why it’s trying to go to this path</p>
<p dir="auto">Error: ENOENT: no such file or directory, access’/home/pi/MagicMirror/js/…/modules/default/currentweather/node_helper.js’</p>
]]></description><link>https://forum.magicmirror.builders/post/87887</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87887</guid><dc:creator><![CDATA[telmini]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:26:43 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:21:59 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> i do not know, screen is hard to read. got enoent  file not found. path is wrong.</p>
]]></description><link>https://forum.magicmirror.builders/post/87886</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87886</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:21:59 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:19:08 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> said in <a href="/post/87882">Config modules from external file (JSON)</a>:</p>
<blockquote>
<p dir="auto">loadJSON(“./modules.json”)</p>
</blockquote>
<p dir="auto">But that bug/crash is inside Magic Mirror code. Or is related to the path defined here “loadJSON(”./modules.json")"?</p>
]]></description><link>https://forum.magicmirror.builders/post/87885</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87885</guid><dc:creator><![CDATA[telmini]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:19:08 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:06:43 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> u have a bad path</p>
<pre><code>/js/ /modules
</code></pre>
<p dir="auto">note modules is off the mm root just like js</p>
<pre><code>/modules/modulename
/js/mm_core_filename.js
</code></pre>
]]></description><link>https://forum.magicmirror.builders/post/87884</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87884</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:06:43 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:03:25 GMT]]></title><description><![CDATA[<p dir="auto">So, it can detect that the json file has the “currentweather” module, but then fails to load it properly.</p>
<p dir="auto">Any help?</p>
]]></description><link>https://forum.magicmirror.builders/post/87883</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87883</guid><dc:creator><![CDATA[telmini]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:03:25 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Wed, 27 Jan 2021 17:00:53 GMT]]></title><description><![CDATA[<p dir="auto">So, I tried this, as seen on another example in this thread</p>
<p dir="auto">config.js:</p>
<pre><code>var config =
{
  address: "0.0.0.0",
  electronOptions: {},
  ipWhitelist: [],
  language: "pt",
  logLevel: ["LOG", "WARN", "ERROR", "DEBUG"],
  modules: loadJSON("./modules.json"),
  paths: {
    modules: "modules",
    vendor: "vendor"
  },
  useHttps: false,
  httpsPrivateKey: "",
  httpsCertificate: ""
};


function loadJSON(filePath){
  if (typeof module !== "undefined") {
        return require(filePath);
    } else {
    var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
    var xhr = new XMLHttpRequest();
		xhr.overrideMimeType("application/json");
		xhr.open("GET", filePath, true);
		xhr.onreadystatechange = function () {
			if (xhr.readyState === 4 &amp;&amp; xhr.status === 200) {
				// needs error handler try/catch at least
				let fileinfo = null;
				try {
					fileinfo = JSON.parse(xhr.responseText);
				} catch (exception) {
					// nothing here, but don't die
					Log.error(" loading json file =" + file + " failed");
				}
				return fileinfo;
			}
		};
		xhr.send(null);
  }
}
</code></pre>
<p dir="auto">modules.json</p>
<pre><code>[{
      "module": "currentweather",
      "position": "top_left",
      "config": {
        "location": "Lisboa",
        "locationID": "2267057",
        "appid": "314d9c29c18fd11e79034c56e1348f4c",
        "iconTable": {
          "01d": "wi-day-sunny",
          "02d": "wi-day-cloudy",
          "03d": "wi-cloudy",
          "04d": "wi-cloudy-windy",
          "09d": "wi-showers",
          "10d": "wi-rain",
          "11d": "wi-thunderstorm",
          "13d": "wi-snow",
          "50d": "wi-fog",
          "01n": "wi-night-clear",
          "02n": "wi-night-cloudy",
          "03n": "wi-night-cloudy",
          "04n": "wi-night-cloudy",
          "09n": "wi-night-showers",
          "10n": "wi-night-rain",
          "11n": "wi-night-thunderstorm",
          "13n": "wi-night-snow",
          "50n": "wi-night-alt-cloudy-windy"
        }
      }
  }]
</code></pre>
<p dir="auto">And this is the output:<br />
![0_1611766820659_output.png](Uploading 100%)</p>
<p dir="auto"><img src="https://imgur.com/a/ALJhNgh" alt="output" class=" img-fluid img-markdown" /></p>
]]></description><link>https://forum.magicmirror.builders/post/87882</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87882</guid><dc:creator><![CDATA[telmini]]></dc:creator><pubDate>Wed, 27 Jan 2021 17:00:53 GMT</pubDate></item><item><title><![CDATA[Reply to Config modules from external file (JSON) on Tue, 26 Jan 2021 00:32:01 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/telmini" aria-label="Profile: telmini">@<bdi>telmini</bdi></a> the browser side also reads config.js  but cannot use file (fs.) operations due to browser security</p>
<p dir="auto">if u can read files  u can read ANY files</p>
]]></description><link>https://forum.magicmirror.builders/post/87814</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/87814</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 26 Jan 2021 00:32:01 GMT</pubDate></item></channel></rss>