# Using Node Red and Forever on Raspberry B+

**URL:** <https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218>\
**Category:** General\
**Created:** [23 October 2018 14:28 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218 "2018-10-23T14:28:58Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [23 October 2018 14:28 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/1 "2018-10-23T14:28:58Z")

</div>

I'm able to start Node Red on my rpi with the following command:

```
sudo /usr/bin/node-red-pi --max-old-space-size=64 --settings .node-red_username/settings.js -u .node-red_username

```

Now i'm trying to use the same command with Forever in this way:

```
sudo /usr/bin/forever start --minUptime 1000 --spinSleepTime 1000 /usr/bin/node-red-pi --max-old-space-size=64 --settings .node-red_username/settings.js -u .node-red_username

```

After this command, using the `sudo forever list` i can see the process, but i can't access to the dashboard with the browser. Does anybody can help me to find the problem? I installed forever with the command `sudo npm install forever -g` . I also tried to increase the minuptime and spinsleeptime up to 10000, but it did'n change anything.

Thank you!

Edit: also tried `sudo /usr/bin/forever start --minUptime 10000 --spinSleepTime 10000 /usr/bin/node-red-pi` without success.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [23 October 2018 14:43 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/2 "2018-10-23T14:43:25Z")

</div>

well you really shouldn’t need to start node-red with sudo, it’s not good practice.

With forever have you looked at the forever error logs? (from memory should be in .forever/ in the hone directory of the user you are using to run it)

---

<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:** [23 October 2018 15:25 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/3 "2018-10-23T15:25:15Z")

</div>

As a matter of interest why can you not just run it as a systemd service in the normal way?

---

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [23 October 2018 15:36 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/4 "2018-10-23T15:36:12Z")

</div>

Unfortunately the logs are empty, i think it's a forever problem because i'm trying to use it also for other programs and it doesn't work.

---

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [23 October 2018 15:37 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/5 "2018-10-23T15:37:28Z")

</div>

I'd like to run multiple instances of node red, and i'm trying to launch them with forever. Do you know other ways to do that? I know i could try with docker, but i wanted to find simpler ways before.

---

<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:** [23 October 2018 15:48 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/6 "2018-10-23T15:48:50Z")

</div>

> [@alcor](#):
>
> I'd like to run multiple instances of node red,

I haven't tried it but if you make a copy `/lib/systemd/system/nodered.service` in the same folder called, for example `nodered1.service`, or some more meaningful name and edit it so that it starts one of your node reds (it is pretty simple, have a look) then you can start it with  
`sudo systemctl start nodered1`  
replacing start with stop or restart as necessary, and to make it run automatically on boot  
`sudo systemctl enable nodered1`  
and use disable to stop it starting automatically. Assuming that works then make additional service files one for each nodered instance.

---

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [23 October 2018 16:18 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/7 "2018-10-23T16:18:44Z")

</div>

Thank you for the suggestion. I found the `nodered.service` file. I didn't find anything about the settings.js path and the user folder, which i inserted in my command:

```auto
sudo /usr/bin/node-red-pi --max-old-space-size=64 --settings .node-red_username/settings.js -u .node-red_username

```

This is the file:

```
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi

Nice=5
Environment="NODE_OPTIONS=--max_old_space_size=256"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTIONS
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

```

Do you know how can i insert the two options `--settings .node-red_username/settings.js -u .node-red_username` ?

---

<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:** [23 October 2018 16:34 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/8 "2018-10-23T16:34:15Z")

</div>

Just stick them on the end of the ExecStart line or add them into the NODE\_OPTIONS definition, that is the command that gets run. Also check that User, Group and WorkingDirectory are what you want. You could change SyslogIdentifier if you wanted so you can separate the logs. Also you could change the Description.

---

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [24 October 2018 11:15 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/9 "2018-10-24T11:15:12Z")

</div>

Ok i tried to edit the file like this:

```
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi/.node-red_username

Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=64"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTION --settings .node-red_username/settings.js -u .node-red_username
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

```

I changed the working directory and i added the options in the ExecStart line. But it doesn't work, except for the original instance on port 1880. Is it possible that i'm using wrong ports? I need 3 instances, and i'm using ports 1880, 1881, 1882.

---

<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:** [24 October 2018 11:37 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/10 "2018-10-24T11:37:03Z")

</div>

If you watch syslog while you start the service by opening a second terminal and running

```auto
tail -f /var/log/syslog

```

then start the service from another terminal window, you should see it starting up.  
My best guess is that the path to the settings file is wrong. You have specified `/home/pi/.node-red_username` as the working dir and then `.node-red_username/settings.js` as the file. I suggest putting the full path for the settings file. In fact with the working directory specified you might not need the settings file spec at all. I don't know. You should see which file it is trying to use from syslog.

---

<div class="post-metadata">

**Author:** ![alcor](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/alcor/32/3275_2.png) [@alcor](https://discourse.nodered.org/u/alcor)\
**Post date:** [24 October 2018 12:07 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/11 "2018-10-24T12:07:10Z")

</div>

> [@Colin](#):
>
> tail -f /var/log/syslog

Yes! That was the problem. Writing twice the path made the rpi looking for the directory .node-red\_username/.node-red\_username . So the file needs only a small edit.

```
# systemd service file to start Node-RED

[Unit]
Description=Node-RED graphical event wiring tool
Wants=network.target
Documentation=http://nodered.org/docs/hardware/raspberrypi.html

[Service]
Type=simple
# Run as normal pi user - change to the user name you wish to run Node-RED as
User=pi
Group=pi
WorkingDirectory=/home/pi/.node-red_username

Nice=5
Environment="NODE_OPTIONS=--max-old-space-size=64"
# uncomment and edit next line if you need an http proxy
#Environment="HTTP_PROXY=my.httpproxy.server.address"
# uncomment the next line for a more verbose log output
#Environment="NODE_RED_OPTIONS=-v"
#ExecStart=/usr/bin/env node $NODE_OPTIONS red.js $NODE_RED_OPTIONS
ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTION --max-old-space-size=64 --settings settings.js
# Use SIGINT to stop
KillSignal=SIGINT
# Auto restart on crash
Restart=on-failure
# Tag things in the log
SyslogIdentifier=Node-RED
#StandardOutput=syslog

[Install]
WantedBy=multi-user.target

```

Thank you for your help 🙂

---

<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:** [24 October 2018 12:42 UTC](https://discourse.nodered.org/t/using-node-red-and-forever-on-raspberry-b/4218/12 "2018-10-24T12:42:00Z")

</div>

Try it without the --settings option, I suspect it will work because settings.js is the default. Also if you look a few lines up from there you will see that NODE\_OPTIONS is already setting max-old-space so you don't need that either. If I am right then it seems that in fact all that is necessary is to change the working directory.
