# Pi - Fail to start as a service

**URL:** <https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803>\
**Category:** General\
**Created:** [26 October 2020 03:29 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803 "2020-10-26T03:29:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 03:29 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/1 "2020-10-26T03:29:31Z")

</div>

I am new to RaspberryPi, and I am sure this is something simple about what the directory I am running out of but...

I can start using

```auto
node-red-pi --max-old-space-size=256

```

but when I run

`node-red-start`

I get

```auto
Starting as a systemd service.
internal/validators.js:120
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.join (path.js:1039:7)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:115:50)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}
nodered.service: Main process exited, code=exited, status=1/FAILURE
nodered.service: Failed with result 'exit-code'.
nodered.service: Service RestartSec=100ms expired, scheduling restart.
nodered.service: Scheduled restart job, restart counter is at 1.

```

---

<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:** [26 October 2020 07:10 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/2 "2020-10-26T07:10:27Z")

</div>

Welcome to the forum.  
How did you install node red? If you used the recommended script it would have set the user and folder to run node red from to that of the user who ran the install script.  
What folder are you running node-red-pi from?  
Look in the node-red.service file to see the user and folder. You can find where that is using  
`sudo systemctl status nodered`  
If those are not right you can edit that file accordingly.

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 14:03 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/3 "2020-10-26T14:03:21Z")

</div>

I tried that, but still got the same error...

I added dome debug code before line 115

```auto
console.log("1");

    console.log(parsedArgs.userDir);
    console.log("2");
    console.log(process.env.HOME);
    console.log("3");
    console.log(parsedArgs.USERPROFILE);
    console.log("4");
    console.log(process.env.HOMEPATH);
        var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red");

```

And it shows all the vars as being undefined:

```auto
Started Node-RED graphical event wiring tool.
1
undefined
2
undefined
3
undefined
4
undefined
internal/validators.js:120
    throw new ERR_INVALID_ARG_TYPE(name, 'string', value);
    ^
TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:120:11)
    at Object.join (path.js:1039:7)
    at Object.<anonymous> (/usr/lib/node_modules/node-red/red.js:124:50)

```

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 14:08 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/4 "2020-10-26T14:08:51Z")

</div>

if I don't run it as a service I get

```auto
1
undefined
2
/home/pi
3
undefined
4
undefined

```

---

<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:** [26 October 2020 15:06 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/5 "2020-10-26T15:06:25Z")

</div>

Can you post the output of  
`sudo systemctl status nodered`  
and also post the nodered.service file that should be shown by that command.

Also what does  
`node -v`  
show?

Finally what directory are you running from when it starts in a terminal?

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 15:22 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/6 "2020-10-26T15:22:21Z")

</div>

sudo systemctl status nodered:

```auto
Warning: The unit file, source configuration file or drop-ins of nodered.service
● nodered.service - Node-RED graphical event wiring tool
   Loaded: loaded (/lib/systemd/system/nodered.service; enabled; vendor preset: 
   Active: inactive (dead) since Mon 2020-10-26 07:09:54 MST; 1h 11min ago
     Docs: http://nodered.org/docs/hardware/raspberrypi.html
  Process: 28814 ExecStart=/usr/bin/env node-red-pi $NODE_OPTIONS $NODE_RED_OPTI
 Main PID: 28814 (code=exited, status=0/SUCCESS)

Oct 26 07:05:13 Pi-NodeRedAutomation Node-RED[28814]: file using your chosen key
Oct 26 07:05:13 Pi-NodeRedAutomation Node-RED[28814]: --------------------------
Oct 26 07:05:13 Pi-NodeRedAutomation Node-RED[28814]: 26 Oct 07:05:13 - [info] S
Oct 26 07:05:13 Pi-NodeRedAutomation Node-RED[28814]: 26 Oct 07:05:13 - [info] S
Oct 26 07:05:13 Pi-NodeRedAutomation Node-RED[28814]: 26 Oct 07:05:13 - [info] S
Oct 26 07:09:54 Pi-NodeRedAutomation Node-RED[28814]: 26 Oct 07:09:54 - [info] S
Oct 26 07:09:54 Pi-NodeRedAutomation Node-RED[28814]: 26 Oct 07:09:54 - [info] S
Oct 26 07:09:54 Pi-NodeRedAutomation systemd[1]: Stopping Node-RED graphical eve
Oct 26 07:09:54 Pi-NodeRedAutomation systemd[1]: nodered.service: Succeeded.
Oct 26 07:09:54 Pi-NodeRedAutomation systemd[1]: Stopped Node-RED graphical even
lines 1-18/18 (END)

```

nodered.service:

```auto
# 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=512"
# 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
```

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 15:22 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/7 "2020-10-26T15:22:57Z")

</div>

node -v v12.18.3

running terminal version from root

---

<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:** [26 October 2020 15:35 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/8 "2020-10-26T15:35:25Z")

</div>

> [@Napalmcsr](#):
>
> running terminal version from root

You shouldn't do that. What happens if you run from the user `pi`'s home directory, not as root?

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 15:41 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/9 "2020-10-26T15:41:58Z")

</div>

ok, if I start the service from pi's home dir, I don't get the errors and node red starts, but my flows have all disappeared.  
If I run from pi's home dir terminal version, my flows are present.

---

<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:** [26 October 2020 15:44 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/10 "2020-10-26T15:44:25Z")

</div>

> [@Napalmcsr](#):
>
> if I start the service from pi's home dir,

I don't understand what you mean by that. What command are you using to start the service.

> [@Napalmcsr](#):
>
> my flows have all disappeared.

That is because you are running as a different user. Your flows will be under root's .node-red folder.

> [@Napalmcsr](#):
>
> If I run from pi's home dir terminal version, my flows are present.

I don't understand what you mean by that either. What command are you running?

---

<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:** [26 October 2020 15:47 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/11 "2020-10-26T15:47:21Z")

</div>

Also, what is on the end of the warning message at the start of sudo systemctl status?

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 15:50 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/12 "2020-10-26T15:50:39Z")

</div>

if I call "node-red-start" from root, the node red fails to start and I get the errors shown in the first post.  
If I call "node-red-start" from /home/pi, node red starts, but all of my flows are gone.

Warning message:  
Warning: The unit file, source configuration file or drop-ins of nodered.service changed on disk. Run 'systemctl daemon-reload' to reload units.

---

<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:** [26 October 2020 16:11 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/13 "2020-10-26T16:11:02Z")

</div>

in your root directory there will be a (hidden) directory call .node-red - all your flows should be in there.  
The easiest would be to copy the entire .node-red directory over to your /home/pi/ directory - you will then have to change ownership of the files so that the pi user can read them - run as user pi  
`sudo cp -R /root/.node-red ~/ && sudo chown -R pi:pi ~/.node-red`

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 16:12 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/14 "2020-10-26T16:12:46Z")

</div>

> [@dceejay](#):
>
> sudo cp -R /root/.node-red ~/ && sudo chown -R pi:pi ~/.node-red

What happened:

```auto
pi@Pi-NodeRedAutomation:~ $ sudo cp -R /root/.node-red ~/ && sudo chown -R pi:pi ~/.node-red
cp: cannot stat '/root/.node-red': No such file or directory

```

and .node-red already exists in home/pi/

---

<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:** [26 October 2020 16:14 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/15 "2020-10-26T16:14:51Z")

</div>

That warning means you edited the service file but have not run `sudo systemctl daemon-reload` to reload it. So you had better do that or reboot  
.

---

<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:** [26 October 2020 16:14 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/16 "2020-10-26T16:14:56Z")

</div>

OK - lets rewind . When you run - node-red-pi and it works... - in the console log it should report the user directory and the flow file name... what are they ?

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 16:16 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/17 "2020-10-26T16:16:47Z")

</div>

```auto
26 Oct 09:16:06 - [info] Node-RED version: v1.2.2
26 Oct 09:16:06 - [info] Node.js version: v12.18.3
26 Oct 09:16:06 - [info] Linux 5.4.51-v7l+ arm LE
26 Oct 09:16:07 - [info] Loading palette nodes
26 Oct 09:16:10 - [info] Dashboard version 2.23.4 started at /ui
26 Oct 09:16:10 - [info] Settings file : /home/pi/.node-red/settings.js
26 Oct 09:16:10 - [info] Context store : 'default' [module=localfilesystem]
26 Oct 09:16:10 - [info] User directory : /home/pi/.node-red
26 Oct 09:16:10 - [warn] Projects disabled : editorTheme.projects.enabled=false
26 Oct 09:16:10 - [info] Flows file : /home/pi/.node-red/flows_Pi-NodeRedAutomation.json
26 Oct 09:16:10 - [info] Server now running at http://127.0.0.1:1880/

```

---

<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:** [26 October 2020 16:19 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/18 "2020-10-26T16:19:49Z")

</div>

ok - great - so stop that - and then run `node-red-start` again as PI... should show you similar  
(this will now be the service - so we can compare...)

---

<div class="post-metadata">

**Author:** ![Napalmcsr](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/napalmcsr/32/30910_2.png) [@Napalmcsr](https://discourse.nodered.org/u/Napalmcsr)\
**Post date:** [26 October 2020 16:20 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/19 "2020-10-26T16:20:34Z")

</div>

As a service

```auto
Welcome to Node-RED
===================
26 Oct 08:58:18 - [info] Node-RED version: v1.2.2
26 Oct 08:58:18 - [info] Node.js version: v12.18.3
26 Oct 08:58:18 - [info] Linux 5.4.51-v7l+ arm LE
26 Oct 08:58:19 - [info] Loading palette nodes
26 Oct 08:58:20 - [info] Settings file : /home/pi/.node-red/settings.js
26 Oct 08:58:20 - [info] Context store : 'default' [module=localfilesystem]
26 Oct 08:58:20 - [info] User directory : /usr/lib/node_modules/node-red/.node-red
26 Oct 08:58:20 - [warn] Projects disabled : editorTheme.projects.enabled=false
26 Oct 08:58:20 - [info] Flows file : /usr/lib/node_modules/node-red/.node-red/flows_Pi-NodeRedAutomation.json

```

---

<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:** [26 October 2020 16:21 UTC](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803/20 "2020-10-26T16:21:01Z")

</div>

@Napalmcsr needs to reload the service file first, or reboot. It has been edited but not reloaded.

[Next page](https://discourse.nodered.org/t/pi-fail-to-start-as-a-service/34803.md?page=2)
