Pi - Fail to start as a service

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

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

but when I run

node-red-start

I get

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.

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.

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

I added dome debug code before line 115

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:

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)

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

1
undefined
2
/home/pi
3
undefined
4
undefined

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?

sudo systemctl status nodered:

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:

# 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

node -v v12.18.3

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?

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.

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

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

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

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

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.

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

What happened:

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/

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
.

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 ?

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/

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...)

As a service

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

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

1 Like