<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>FAQ on Much Ado About IT</title><link>https://it.knightnet.org.uk/tags/faq/</link><description>
Recent content about FAQ from Much Ado About IT |
Ramblings and rantings from IT Architect &amp; Designer, Julian Knight</description><generator>Hugo | gohugo.io | Theme twenty-sixteen</generator><language>en-gb</language><copyright>This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.</copyright><lastBuildDate>Mon, 24 Apr 2023 21:27:28 +0000</lastBuildDate><atom:link href="https://it.knightnet.org.uk/tags/faq/feed.xml" rel="self" type="application/rss+xml"/><item><title>FAQ 4: How do I see the Node-RED log?</title><link>https://it.knightnet.org.uk/kb/nr-qa/faq4-show-node-red-log/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/faq4-show-node-red-log/</guid><pubDate>Tue, 17 Mar 2020 16:28:07 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/faq4-show-node-red-log/</guid><description><div>Just as there are several possible ways to run Node-RED, there are several ways to access the log.</div><div>&lt;p>In line with most server type applications, Node-RED outputs all sorts of operational and error information to a log. In addition to Node-RED&amp;rsquo;s own logging, each node that you use may also add to the log.&lt;/p>
&lt;p>You can also output your own information to the log from your flows, those methods are shown at the end of this article.&lt;/p>
&lt;p>There are three categories of ways to actually run Node-RED and each will require you to access the log in a slightly different way.&lt;/p>
&lt;h2 id="running-node-red-as-a-service">Running Node-RED as a &amp;ldquo;Service&amp;rdquo;&lt;/h2>
&lt;p>If you install Node-RED using the script supplied for installation on a Raspberry Pi (or any other Debian-like host), Node-RED will be run as a system service. That is to say that it will be started up when the system boots. You can also do this on other platforms including Windows.&lt;/p>
&lt;h3 id="linux">Linux&lt;/h3>
&lt;p>In these cases, typically system log output goes to a standard service such as &lt;code>syslog&lt;/code>. Typically, the syslog output is found in a file at &lt;code>/var/log/syslog&lt;/code> and you can use the &lt;code>tail&lt;/code> command from a terminal command prompt to view it.&lt;/p>
&lt;p>On most modern versions of Linux though, the syslog is being overtaken by logging built into the &lt;code>systemd&lt;/code> service. In these cases, it is better to use the &lt;code>journalctl&lt;/code> command to show the log output. This has the advantage that you only need to know the service name (&lt;code>node-red&lt;/code> on a standard Pi install) and you don&amp;rsquo;t need to worry about where the actual data is stored. You can also use the more advanced features of that command to output logs in different formats.&lt;/p>
&lt;p>The following command will show you the last 50 lines of the log, jumps to the last output and &amp;ldquo;follows&amp;rdquo; any further output.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">journalctl -u node-red -e -f -n &lt;span class="m">50&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;h3 id="windows">Windows&lt;/h3>
&lt;p>Windows does not use log output in the same way that Linux does as it has the &amp;ldquo;Event Logs&amp;rdquo;. Typically, log output is redirected to a file and you will need to look at the startup command for Node-RED to see where the logs are being written to.&lt;/p>
&lt;h2 id="running-node-red-manually">Running Node-RED manually&lt;/h2>
&lt;p>On all platforms, if you run Node-RED manually from the command line, the log output is shown in the same terminal. Using the keyboard command &lt;!-- raw HTML omitted -->ctrl&lt;!-- raw HTML omitted -->-&lt;!-- raw HTML omitted -->c&lt;!-- raw HTML omitted --> will both stop Node-RED and close the log.&lt;/p>
&lt;h2 id="using-a-runner-to-run-node-red">Using a &amp;ldquo;runner&amp;rdquo; to run Node-RED&lt;/h2>
&lt;p>Sometimes, especially during development, it is helpful to use a &amp;ldquo;runner&amp;rdquo; application such as &lt;code>PM2&lt;/code> or &lt;code>nodemon&lt;/code> to start Node-RED. These will recover from failures and can be made to &amp;ldquo;watch&amp;rdquo; for changes to files and restart automatically.&lt;/p>
&lt;p>Each of these tools may have their own ways of viewing log output. For example, when using the popular pm2 runnner, the command is &lt;code>pm2 logs&lt;/code>.&lt;/p>
&lt;hr>
&lt;h2 id="changing-log-output-levels">Changing log output levels&lt;/h2>
&lt;p>By default, Node-RED will show the following types of output from both Node-RED and any installed nodes:&lt;/p>
&lt;ul>
&lt;li>&lt;code>fatal&lt;/code> - only those errors which make the application unusable should be recorded&lt;/li>
&lt;li>&lt;code>error&lt;/code> - record errors which are deemed fatal for a particular request + fatal errors&lt;/li>
&lt;li>&lt;code>warn&lt;/code> - record problems which are non fatal + errors + fatal errors&lt;/li>
&lt;li>&lt;code>info&lt;/code> - record information about the general running of the application + warn + error + fatal errors&lt;/li>
&lt;/ul>
&lt;p>You can change the logging levels to also show:&lt;/p>
&lt;ul>
&lt;li>&lt;code>debug&lt;/code> - record information which is more verbose than info + info + warn + error + fatal errors&lt;/li>
&lt;li>&lt;code>trace&lt;/code> - record very detailed logging + debug + info + warn + error + fatal errors&lt;/li>
&lt;/ul>
&lt;p>Or you can remove levels or turn off logging alltogether (using the &lt;code>off&lt;/code> setting).&lt;/p>
&lt;p>In addition, there are 2 other settings that impact logs:&lt;/p>
&lt;ul>
&lt;li>&lt;code>metrics&lt;/code> - Whether or not to include metric events in the log output&lt;/li>
&lt;li>&lt;code>audit&lt;/code> - Whether or not to include audit events in the log output&lt;/li>
&lt;/ul>
&lt;p>All of these settings are found (complete with instructions) in the &lt;code>settings.js&lt;/code> file typically found in the &lt;code>userDir&lt;/code> folder (normally &lt;code>~/.node-red/settings.js&lt;/code>).&lt;/p>
&lt;h2 id="outputting-your-own-information-to-the-log">Outputting your own information to the log&lt;/h2>
&lt;p>When writing flows in Node-RED, you will normally use the &lt;code>debug&lt;/code> node that, by default, outputs to the debug sidebar in the Node-RED Editor (admin UI). However, you can change the settings in the debug node to also (or instead) output to the log.&lt;/p>
&lt;p>&lt;img src="https://it.knightnet.org.uk/static/uploads/2020/node-red-debug-node-settings.jpg" alt="node-red debug node settings">&lt;/p>
&lt;p>In addition, you can also output to the log from a &lt;code>function&lt;/code> node using the code:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-javascript" data-lang="javascript">&lt;span class="line">&lt;span class="cl">&lt;span class="nx">node&lt;/span>&lt;span class="p">.&lt;/span>&lt;span class="nx">warn&lt;/span>&lt;span class="p">(&lt;/span>&lt;span class="s1">&amp;#39;some useful text&amp;#39;&lt;/span>&lt;span class="p">)&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>Output:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">Mar &lt;span class="m">17&lt;/span> 17:12:48 pi node-red&lt;span class="o">[&lt;/span>18577&lt;span class="o">]&lt;/span>: &lt;span class="m">17&lt;/span> Mar 17:12:48 - &lt;span class="o">[&lt;/span>warn&lt;span class="o">]&lt;/span> &lt;span class="o">[&lt;/span>&lt;span class="k">function&lt;/span>:My useful fn node&lt;span class="o">]&lt;/span> some useful text
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If you give your function node a reasonably name, you will see that in the output as shown. If the node doesn&amp;rsquo;t have a name, the id will be shown, you can use that in the Editor&amp;rsquo;s search feature to find the node.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/faq">FAQ</category></item><item><title>FAQ 3: What different ways are there to install Node-RED and which is best?</title><link>https://it.knightnet.org.uk/kb/nr-qa/faq3-types-of-installation/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/faq3-types-of-installation/</guid><pubDate>Tue, 10 Mar 2020 09:26:00 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/faq3-types-of-installation/</guid><description><div>There are several possible ways to install Node-RED, this post provides an overview and some thoughts about when you might want to use which approach.</div><div>&lt;p>There are three basic approaches to installing Node-RED. Which of these is &amp;ldquo;best&amp;rdquo; for you will depend on your knowledge, willingness to learn, desire or need to gain maximum flexibility and so on. Only you can work that out. It should also be noted that you should be able to mix and max these approaches if you really want to (though I can&amp;rsquo;t say that I would personally recommend that).&lt;/p>
&lt;h2 id="global-install">Global Install&lt;/h2>
&lt;ul>
&lt;li>This is the standard and therefore arguably by far the easiest installation.&lt;/li>
&lt;li>It is good for people who are not overly familiar with their OS&amp;rsquo;s filing system or how node.js and npm work and who don&amp;rsquo;t want to be bothered to find out (that is not a criticism by the way).&lt;/li>
&lt;li>It allows for multiple instances to be run if needed but all instances must use the same version of Node-RED.&lt;/li>
&lt;li>It doesn&amp;rsquo;t &amp;ldquo;pollute&amp;rdquo; your home folder with the node-red and many other required node.js modules.&lt;/li>
&lt;li>It is standard and most tutorials and explanations assume that this is the way it is installed.&lt;/li>
&lt;li>It makes the node-red command global so you can run it from anywhere.&lt;/li>
&lt;/ul>
&lt;h3 id="advantages">Advantages&lt;/h3>
&lt;p>Best for beginners unless you are prepared to learn about Node.js.&lt;/p>
&lt;h3 id="disadvantages">Disadvantages&lt;/h3>
&lt;p>Less flexible and possibly a little less secure. Not the best for &amp;ldquo;production&amp;rdquo; installations. Can confuse beginners into installing other Nodes and packages into global when they shouldn&amp;rsquo;t. Hard to work out where the global files are.&lt;/p>
&lt;h2 id="local-install">Local Install&lt;/h2>
&lt;ul>
&lt;li>This is a more &amp;ldquo;node.js way&amp;rdquo; of installing - global installations being good for exposing global commands but may sometimes be less secure.&lt;/li>
&lt;li>It is a more self-contained installation. Everything can be in 1 place under a single folder structure. This makes it easier to back-up everything together. But it doesn&amp;rsquo;t force you to work this way, you can keep your userDir folder separate if you like.&lt;/li>
&lt;li>It allows you to run different instances of Node-RED using different versions. Good for testing major Node-RED upgrades and for testing custom nodes or flows against different versions.&lt;/li>
&lt;li>You are in control. You know where everything is because you chose to put it there.&lt;/li>
&lt;li>You control access to all files and folders and so this can be a more flexible installation. You could also have different instances of node-red on the same device with different folder/file access levels. Possible development and test instances on the same device.&lt;/li>
&lt;li>A good way to create a more portable installation of Node-RED since the whole folder structure can be easily copied/archived, etc.&lt;/li>
&lt;li>It is my personal belief that this is also the best approach for people who want to learn how Node.js and/or Node-RED works. But then again, maybe that&amp;rsquo;s just my warped mind!&lt;/li>
&lt;/ul>
&lt;h3 id="advantages-1">Advantages&lt;/h3>
&lt;p>Best for flexibility and control. Good for control of security. Best for running different versions of Node-RED in parallel on one device. Good for ease of backup/recovery and for creating distributable copies of a Node-RED application. Best for embedding Node-RED into an existing or new Node.js app.&lt;/p>
&lt;h3 id="disadvantages-1">Disadvantages&lt;/h3>
&lt;p>Requires some knowledge of how Node.js and npm work.&lt;/p>
&lt;h2 id="containerised-install">Containerised Install&lt;/h2>
&lt;ul>
&lt;li>Uses either Docker or snap to containerise the installation.&lt;/li>
&lt;li>Isolates Node-RED from the host OS.&lt;/li>
&lt;li>Allow running multiple, independent instances of Node-RED, possible using different versions.&lt;/li>
&lt;/ul>
&lt;h3 id="advantages-2">Advantages&lt;/h3>
&lt;p>Best for enterprise use where containerisation is already well supported.&lt;/p>
&lt;h3 id="disadvantages-2">Disadvantages&lt;/h3>
&lt;p>Adds significant hidden complexity and requires good knowledge of the container technology to isolate and fix issues. Also likely to have higher resource requirements than running separate instances in other ways. Experience from the Node-RED forum suggests that a decent knowledge of Docker/snap is recommended.&lt;/p>
&lt;hr>
&lt;p>There is some additional information that I wrote in a recent blog post:&lt;/p>
&lt;p>&lt;a href="https://it.knightnet.org.uk/kb/nr-qa/faq2-multiple-instances/">https://it.knightnet.org.uk/kb/nr-qa/faq2-multiple-instances/&lt;/a>&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/faq">FAQ</category></item><item><title>FAQ 2: How can I run multiple instances of Node-RED on the same server device?</title><link>https://it.knightnet.org.uk/kb/nr-qa/faq2-multiple-instances/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/faq2-multiple-instances/</guid><pubDate>Fri, 06 Mar 2020 01:21:33 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/faq2-multiple-instances/</guid><description><div>There are all sorts of reasons to want to run more than a single instance of Node-RED and several ways to do it.</div><div>&lt;ol>
&lt;li>
&lt;p>Use the command line settings to point to a different userDir folder.&lt;/p>
&lt;p>&lt;code>node-red -u /data/userDirectory&lt;/code>&lt;/p>
&lt;p>That lets you use different flows and configuration settings but only allows a single version of Node-RED.&lt;/p>
&lt;p>You still install Node-RED in the &amp;ldquo;standard&amp;rdquo; way, globally. While this is generally simpler for complete beginners,
it can lead to complexities later on. You should understand the strengths and weaknesses of npm global installs.&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Install the Node-RED npm package locally rather than globally.&lt;/p>
&lt;p>This gives you not only the features from 1 but also allows you to run different versions of Node-RED in parallel. The &lt;a href="https://github.com/TotallyInformation/alternate-node-red-installer">alternate-node-red-installer&lt;/a> shows you how to do that.&lt;/p>
&lt;p>It also removes the need to install Node-RED globally which can lead to unexpected security issues.&lt;/p>
&lt;p>This is also the &amp;ldquo;Node.JS way&amp;rdquo; and likely to be a more welcome approach for organisations and teams that run other Node.JS services and systems.&lt;/p>
&lt;p>While slightly more complex to think about initially, especially for Node.JS beginners, it helps you understand how Node.js works, is easier
to work out where everything is kept and is likely to be easier to maintain in the longer term.&lt;/p>
&lt;p>I use npm&amp;rsquo;s script capability to make things really easy to start manually. Here are some examples. Note that I always make the &lt;code>userDir&lt;/code> folder a sub-folder of the master project folder (where Node-RED itself is installed). Keeps things neat and makes it trivial to backup the whole thing.&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-json" data-lang="json">&lt;span class="line">&lt;span class="cl">&lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;scripts&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="p">{&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;start&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;node node_modules/node-red/red.js --userDir ./data&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;start2&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;set DEBUG=express:* &amp;amp; nodemon node_modules/node-red/red.js --userDir ./data&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;inspect&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;node --inspect node_modules/node-red/red.js --userDir ./data&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;log&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;sudo journalctl -u node-red -f -n 0 -o cat&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="nt">&amp;#34;update&amp;#34;&lt;/span>&lt;span class="p">:&lt;/span> &lt;span class="s2">&amp;#34;npm install --unsafe-perm --production node-red&amp;#34;&lt;/span>&lt;span class="p">,&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="p">},&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl"> &lt;span class="err">...&lt;/span>
&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="p">}&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>So you can start manually using &lt;code>npm start&lt;/code> and start with debugging port active using &lt;code>npm run inspect&lt;/code>&lt;/p>
&lt;/li>
&lt;li>
&lt;p>Run Node-RED in a container such as the &lt;a href="https://github.com/node-red/node-red-docker">Docker container&lt;/a>.&lt;/p>
&lt;p>Allows multiple versions of Node-RED along with different configurations and supporting software and services.&lt;/p>
&lt;p>However, this comes at the cost of significantly greater complexity and resource overheads.
Unlikely to be worth doing except in specific circumstances &amp;amp; needs a reasonable level of understanding
of how Docker works.&lt;/p>
&lt;/li>
&lt;/ol>
&lt;p>You will realise that I much prefer method 2 for all of my own installations. That&amp;rsquo;s why I wrote the alternate installer which
goes some way towards making installations easier and more consistent.&lt;/p>
&lt;p>For running Node-RED on system startup, please see the &lt;a href="https://nodered.org/docs/faq/starting-node-red-on-boot"> Starting Node-RED on boot&lt;/a> page in the docs.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/faq">FAQ</category></item><item><title>FAQ 1: Should I use a function node or a flow of core nodes?</title><link>https://it.knightnet.org.uk/kb/nr-qa/faq1-flow-vs-function/</link><guid isPermaLink="true">https://it.knightnet.org.uk/kb/nr-qa/faq1-flow-vs-function/</guid><pubDate>Fri, 06 Mar 2020 01:16:35 +0000</pubDate><guid>https://it.knightnet.org.uk/kb/nr-qa/faq1-flow-vs-function/</guid><description><div>There are usually many ways to achieve something in Node-RED. A common question is whether or when to use a function node or a collection of core nodes to achieve an outcome.</div><div>&lt;p>Whether I use one approach or the other depends on the complexity of the input vs the complexity of the output.
It really doesn&amp;rsquo;t matter except that it is often easier to read a single function node that several complex change nodes as an example.&lt;/p>
&lt;p>So my general rules of thumb for whether to replace a collection of nodes with a function node are:&lt;/p>
&lt;ul>
&lt;li>How difficult would this be to do in a pure flow? If it is just a couple of nodes, that&amp;rsquo;s fine, if it is 10 nodes then probably not fine.&lt;/li>
&lt;li>If I am using JSONata, how long is it taking me to puzzle over the JSONata code? If it is a few minutes then fine, otherwise use a function node!&lt;/li>
&lt;li>Did someone already write some JavaScript that I can purloin? If so then use it!&lt;/li>
&lt;/ul>
&lt;p>Of course, I know JavaScript reasonably well and if you don&amp;rsquo;t then your own rules might look a little different.&lt;/p></div></description><author>Julian Knight</author><category domain="https://it.knightnet.org.uk/categories/development">Development</category><category domain="https://it.knightnet.org.uk/tags/node-red">Node-RED</category><category domain="https://it.knightnet.org.uk/tags/faq">FAQ</category></item></channel></rss>