<?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[Using npm module in a module]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I just started with MagicMirror, and now I want to write my own MM module.<br />
Is there any documentation on how to use an npm module in an MM module?</p>
<p dir="auto">Thanks,</p>
<p dir="auto">Pascal</p>
]]></description><link>https://forum.magicmirror.builders/topic/12228/using-npm-module-in-a-module</link><generator>RSS for Node</generator><lastBuildDate>Tue, 11 Aug 2026 09:04:10 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/12228.rss" rel="self" type="application/rss+xml"/><pubDate>Mon, 17 Feb 2020 20:46:41 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Using npm module in a module on Tue, 18 Feb 2020 13:19:34 GMT]]></title><description><![CDATA[<p dir="auto">be careful loading lots of services in the modulename.js via getscripts… all that is loaded into the browser… (and every instance of the browser used)</p>
<p dir="auto">load them in the node_helper via require as single instance,  and move the memory and load to the server side</p>
]]></description><link>https://forum.magicmirror.builders/post/69688</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/69688</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Tue, 18 Feb 2020 13:19:34 GMT</pubDate></item><item><title><![CDATA[Reply to Using npm module in a module on Tue, 18 Feb 2020 08:24:48 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/prapicault" aria-label="Profile: prapicault">@<bdi>prapicault</bdi></a> said in <a href="/post/69678">Using npm module in a module</a>:</p>
<blockquote>
<p dir="auto">add my dependencies to this new file, then npm install</p>
</blockquote>
<p dir="auto">Great!<br />
Instead of manually adding dependencies to package.json you can as well install the module with a <code>--save</code>flag</p>
<pre><code>npm install axios --save
</code></pre>
<p dir="auto">Automatically adds it as dependency to package.json.</p>
<pre><code>npm uninstall axios --save
</code></pre>
<p dir="auto">automatically removes it from package.json.</p>
]]></description><link>https://forum.magicmirror.builders/post/69685</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/69685</guid><dc:creator><![CDATA[lavolp3]]></dc:creator><pubDate>Tue, 18 Feb 2020 08:24:48 GMT</pubDate></item><item><title><![CDATA[Reply to Using npm module in a module on Tue, 18 Feb 2020 03:54:50 GMT]]></title><description><![CDATA[<p dir="auto">Thanks you both. I’ve managed to get going by:</p>
<ul>
<li>adding a package.json file to my MM module (<code>npm init --yes</code>)</li>
<li>add my dependencies to this new file, then <code>npm install</code></li>
<li>add a getScripts entry in my main js file, referencing the various dependencies included in my module</li>
</ul>
]]></description><link>https://forum.magicmirror.builders/post/69678</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/69678</guid><dc:creator><![CDATA[prapicault]]></dc:creator><pubDate>Tue, 18 Feb 2020 03:54:50 GMT</pubDate></item><item><title><![CDATA[Reply to Using npm module in a module on Mon, 17 Feb 2020 21:52:54 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/prapicault" aria-label="Profile: prapicault">@<bdi>prapicault</bdi></a>  In addition to that, the require method is used in node_helper.js files. As far as I know the require function does not work in the main module .js file. You need to reference the (main) script of the node module via the function <code>getscripts</code> there.</p>
<p dir="auto">All scripts included are of course installed via console: <code>npm install NODE_MODULE</code></p>
<p dir="auto">An example of using them in both environments:</p>
<p dir="auto">node_helper.js file</p>
<pre><code>var NodeHelper = require('node_helper');
var request = require('request');
</code></pre>
<p dir="auto">very easy, you can now use <code>request</code> as a function.</p>
<p dir="auto">A bit different with the main MMM-module.js file:</p>
<pre><code>  // Define required scripts. Chart.js needed for the graph.
  getScripts: function() {
    return [
      'modules/MMM-Buienalarm/node_modules/chart.js/dist/Chart.bundle.js',
    ];
  },
</code></pre>
<p dir="auto">Basically, the script is appended to the one you’re writing. Now you can use the functions integrated in the referenced script.</p>
]]></description><link>https://forum.magicmirror.builders/post/69658</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/69658</guid><dc:creator><![CDATA[lavolp3]]></dc:creator><pubDate>Mon, 17 Feb 2020 21:52:54 GMT</pubDate></item><item><title><![CDATA[Reply to Using npm module in a module on Mon, 17 Feb 2020 20:56:12 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/prapicault" aria-label="Profile: prapicault">@<bdi>prapicault</bdi></a> the nodejs npm modules are used by the require() clause</p>
<p dir="auto">var xxxx  = require(‘nom_module_name’)</p>
<p dir="auto">then see the services (methods) provided there…<br />
see my sample module here</p>
<p dir="auto"><a href="https://github.com/sdetweil/SampleModule" target="_blank" rel="noopener noreferrer nofollow ugc">https://github.com/sdetweil/SampleModule</a></p>
]]></description><link>https://forum.magicmirror.builders/post/69653</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/69653</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Mon, 17 Feb 2020 20:56:12 GMT</pubDate></item></channel></rss>