# How to install node red and recognizer

**URL:** <https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249>\
**Category:** General\
**Created:** [22 October 2023 07:50 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249 "2023-10-22T07:50:51Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [27 October 2023 16:49 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/43 "2023-10-27T16:49:45Z")

</div>

Yes, it does just that. 🙂  
The bottom line is that my script doesn't run when I `sudo node red start...`.  
Only when `node red start.....`  
I test it `printenv`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 October 2023 16:54 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/44 "2023-10-27T16:54:32Z")

</div>

> [@azxo1](#):
>
> The bottom line is that my script doesn't run when I `sudo node red start...`.  
> Only when `node red start.....`

That does not make sense. Do you mean your script runs if you use  
`node-red`  
but not if you use  
`sudo systemctl start nodered`  
The first runs node red in the command window environment, the second runs it as a systemd service. The difference is not the sudo, it is the way it is being run that is different.  
If it is as I have described then it is the environment difference that is causing the problem, so try printenv as I suggested.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [27 October 2023 16:57 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/45 "2023-10-27T16:57:30Z")

</div>

That makes sense. 🙂  
I'm testing printenv now

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [27 October 2023 17:02 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/46 "2023-10-27T17:02:16Z")

</div>

GalZoli@raspberrypi:~ $ sudo node-red-start

printenv :

LANGUAGE=hu\_HU.UTF-8  
USER=GalZoli  
HOME=/home/GalZoli  
OLDPWD=/usr/lib/node\_modules/node-red/bin  
NODE\_OPTIONS=--max\_old\_space\_size=1024  
LOGNAME=GalZoli  
JOURNAL\_STREAM=8:14428  
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin  
INVOCATION\_ID=428915xxxxxxxxxxx69d26d  
LANG=hu\_HU.UTF-8  
SHELL=/bin/bash  
PWD=/home/GalZoli  
NODE\_RED\_HOME=/usr/lib/node\_modules/node-red  
NTBA\_FIX\_319=1  
PYTHONUNBUFFERED=1

/////////////////////////////////////////////////////////////////////////

GalZoli@raspberrypi:~ $ node-red

printenv :

SHELL=/bin/bash  
LANGUAGE=hu\_HU.UTF-8  
NO\_AT\_BRIDGE=1  
PWD=/home/GalZoli  
LOGNAME=GalZoli  
XDG\_SESSION\_TYPE=tty  
MOTD\_SHOWN=pam  
HOME=/home/GalZoli  
LANG=hu\_HU.UTF-8  
LS\_COLORS=rs=0:di=01;3............... etc

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [27 October 2023 17:04 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/47 "2023-10-27T17:04:37Z")

</div>

> [@Colin](#):
>
> That does not make sense. Do you mean your script runs if you use  
> `node-red`  
> but not if you use  
> `sudo systemctl start nodered`

That's exactly what I mean! 😃

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 October 2023 17:19 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/48 "2023-10-27T17:19:43Z")

</div>

Probably something in there is making the difference.

---

<div class="post-metadata">

**Author:** ![azxo1](https://avatars.discourse-cdn.com/v4/letter/a/b487fb/32.png) [@azxo1](https://discourse.nodered.org/u/azxo1)\
**Post date:** [27 October 2023 17:52 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/49 "2023-10-27T17:52:59Z")

</div>

I moved my script to the .node-red folder. debug bigexec:

> : Error terminating PortAudio: PortAudio not initialized [PaErrorCode -10000]

> ```
> _terminate() File "/home/GalZoli/.local/lib/python3.9/site-packages/sounddevice.py", line 2851, in _terminate
> 
> ```

> Expression 'parameters-\>channelCount \<= maxChans' failed in 'src/hostapi/alsa/pa\_linux\_alsa.c', line: 1513  
> Expression 'ValidateParameters( inputParameters, hostApi, StreamDirection\_In )' failed in 'src/hostapi/alsa/pa\_linux\_alsa.c', line: 2813

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [27 October 2023 19:25 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/50 "2023-10-27T19:25:11Z")

</div>

> [@azxo1](#):
>
> sudo node-red-start

This results in this:

```auto
NODE_RED_HOME=/usr/lib/node_modules/node-red

```

So your Node-RED userDir is in a location only accessible to root. Also, Node-RED can now to ANYTHING to your system. See the recent thread on hacked instances if you need more help in understanding why this is a bad idea. But also, one slip of a flow could easily destroy your whole system.

For example, run an exec node with the command `rm -R /etc` (hint - really don't run that!)

You also aren't telling us some important stuff. When you say your script doesn't run, do you mean Node-RED itself doesn't run - and if so, please show use the error log. Or simply that your flow doesn't run - in which case show use the errors from your flow.

> [@azxo1](#):
>
> : Error terminating PortAudio: PortAudio not initialized [PaErrorCode -10000]

Is this the error from your flow? If so, this proves what people have been trying to tell you. When you run Node-RED in the way that fails, it is because ALSA can't run because the environment is wrong.

None of this has anything to do with Node-RED itself. Sort out running Node-RED correctly first, then sort out the ALSA environment.

* * *

PS: In my view, Audio is a bag of spanners on Linux. If it doesn't work first time, you will probably spend weeks hunting through forums trying to get it to work - at least that's my experience.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [27 October 2023 20:50 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/51 "2023-10-27T20:50:49Z")

</div>

> [@TotallyInformation](#):
>
> > [@azxo1](#):
> >
> > sudo node-red-start
> 
> This results in this:
> 
> ```auto
> NODE_RED_HOME=/usr/lib/node_modules/node-red
> 
> ```

I don't think that is correct. `node-red-start` runs `sudo systemctl start nodered` so sudo should make little difference.  
`sudo node-red` is definitely a bad idea though.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [27 October 2023 21:00 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/52 "2023-10-27T21:00:16Z")

</div>

> [@Colin](#):
>
> `sudo node-red` is definitely a bad idea though.

I tested sudo node-red.

It says

`Starting as root systemd service.`

But the node-red process is still owned by pi. (systemd always runs as root, username is derived from systemd script.)  
`pi 2154269 1 58 21:55 ? 00:00:22 node-red`

I can't see any difference in the environment within Node-red started like that or sudo systemctl start nodered.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 October 2023 07:35 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/53 "2023-10-28T07:35:00Z")

</div>

> [@jbudd](#):
>
> I tested sudo node-red.
> 
> It says
> 
> `Starting as root systemd service.`

Are you sure that was from `sudo node-red`?

What does this show  
`which node-red`  
I would expect it to say /usr/bin/node-red, and if you look in that file I would expect it to start with

```auto
#!/usr/bin/env node
/**
 * Copyright JS Foundation and other contributors, http://js.foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/

if (process.argv[2] === 'admin') {
    try {
        require("node-red-admin")(process.argv.slice(3)).catch(err => {
            process.exit(1);
        })
    } catch(err) {

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [28 October 2023 08:58 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/54 "2023-10-28T08:58:38Z")

</div>

> [@Colin](#):
>
> Are you sure that was from `sudo node-red`?

Nope. It was sudo node-red-start.  
Can I blame autocomplete?

sudo node-red does indeed start it as root with User directory : /root/.node-red and which node-red is /usr/bin/node-red

I've always found it confusing that you can start Node-red with `node-red`, `node-red start` or `node-red-start` but the right way seems to be `sudo systemctl start nodered`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 October 2023 09:45 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/55 "2023-10-28T09:45:32Z")

</div>

> [@jbudd](#):
>
> node-red start

That starts node red, expecting the files file to be in a file called start, so you probably never want to do that.  
node-red-start runs the systemctl command to start node red as a service and then shows the node red log in the terminal. I normally use node-red-start, there is normally little need to use the command `node-red` on a pi.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 October 2023 09:53 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/56 "2023-10-28T09:53:19Z")

</div>

node-red - starts Node-RED as the current user in the users environment.  
sudo systemctl start nodered - start Node-RED as a system service using the user specified in the service file. Useful for starting long running service that keeps running if you close session.  
node-red-start - easier to type alias for above that also then tails the log file so you see what is happening. This is the recommended way to do it.  
node-red start - starts Node-RED as the local user with a parameter ( the flow file name) of start. Def wrong way to do it.

Also ( if installed using our script)  
node-red-stop - stops the service  
node-red-log - just tail the current log file.  
node-red-reload - stop and restart the service

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 October 2023 11:13 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/57 "2023-10-28T11:13:53Z")

</div>

It is for these reasons I learn to start and stop things directly and learn the direct way to install and update things - so that I don't confuse myself.

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [28 October 2023 13:00 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/58 "2023-10-28T13:00:04Z")

</div>

> [@dceejay](#):
>
> node-red-start - easier to type alias for above that also then tails the log file so you see what is happening. This is the recommended way to do it.

I find tailing the log file a pain in the tail! 😄  
But on the occasions when I do want to see the output, eg after a reinstall, I find `node-red` does the job.

> [@dceejay](#):
>
> node-red start - starts Node-RED as the local user with a parameter ( the flow file name) of start. Def wrong way to do it.

I almost always use `sudo systemctl restart nodered`.  
But if you search through this forum you can find many examples of people saying they ran `node-red start`

If as a beginner you do run `node-red start` you get an empty editor, no sign that you made a mistake. If you deploy it creates a flowfile called start (not start.json) and now _you must always use_ `node-red start` to see your flows.

Perhaps the node-red script would be better if it accepted a flag -f flowfilename and to avoid breaking changes, a warning if a parameter was used as the flow file name without this flag?

ps See [this thread](https://discourse.nodered.org/t/raspberry-pi-hangs-up-at-node-red-start/3181) for an example of mutual misunderstandings around the start-up command

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 October 2023 14:07 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/59 "2023-10-28T14:07:56Z")

</div>

> [@jbudd](#):
>
> I find tailing the log file a pain in the tail!

I simply put the journalctl command in to the package.json scripts then I don't have to remember the command.

> [@jbudd](#):
>
> I almost always use `sudo systemctl restart nodered`.

Again, I put that into package.json. So I can do:

```auto
npm restart

```

or

```auto
npm log

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [28 October 2023 15:12 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/60 "2023-10-28T15:12:01Z")

</div>

> [@TotallyInformation](#):
>
> Again, I put that into package.json. So I can do:
> 
> `npm restart`

Well yes. You can do `sudo service nodered restart` too.  
The point I wanted to highlight was that a lot of people say they start Node-red in a manner which @dceejay says is "Def[initely] the wrong way" because of the whole hyphen/no hyphen confusion, and the startup script could be tweeked to warn them.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [28 October 2023 15:41 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/61 "2023-10-28T15:41:31Z")

</div>

Or the right commands could be baked into the package.json file. 😉

But I am not disagreeing with you.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [28 October 2023 15:43 UTC](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249/62 "2023-10-28T15:43:21Z")

</div>

> [@jbudd](#):
>
> the startup script could be tweeked to warn them.

When you run “node-red” anything it invokes node-red directly skipping any script. So nothing can be tweaked there. It would need to be in the core.

[Previous page](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249.md?page=2)

[Next page](https://discourse.nodered.org/t/how-to-install-node-red-and-recognizer/82249.md?page=4)
