i want to run the Modbus Flex Server from the module node-red-contrib-modbus on an Raspberry Pi with Raspbian. But whenever i use the default port 502, Node-Red crashes. I found out that, ports below 1024 can not used without root. Then i found the command setcap 'cap_net_bind_service=+ep' [path to node] to have access without running as root.
But now i tried it but it won't work either. I'm not sure i'm using the correct path.
I'm using setcap 'cap_net_bind_service=+ep' /home/pi/.node-red/node_modules/node-red-contrib-modbus/modbus/modbus-flex-server.js
Maybe someone can tell me what i'm doing wrong or give me a solution.
I searched for a while and can't another way to solve it.
I have not done that but I am sure it will not be the path to the node, it may be the path to the nodejs executable. In which case, on a pi, it may be /usr/bin/node so you could try that.
Note that this may be a security risk as it means any nodejs application will have those access rights. Whether that is an issue for you depends on the environment you are running in.
Where possible please copy/paste terminal output rather than screenshot. When pasting use the </> button at the top of the forum entry window. Thanks.
Can you copy/paste the setcap command you are using and any output it produces please. Also run the command with -v and show us that too. So netcap -v 'cap_net_....
pi@raspberrypi:~ $ sudo setcap -v CAP_NET_BIND_SERVICE=+eip /usr/bin/node
/usr/bin/node: OK
And this is the output i get from Node-Red:
pi@raspberrypi:~ $ ./node-red
24 Jan 11:31:44 - [info]
Willkommen bei Node-RED!
===================
24 Jan 11:31:44 - [info] Node-RED Version: v1.2.7
24 Jan 11:31:44 - [info] Node.js Version: v14.15.4
24 Jan 11:31:44 - [info] Linux 5.4.79-v7l+ arm LE
24 Jan 11:31:45 - [info] Paletten-Nodes werden geladen
24 Jan 11:31:48 - [info] Einstellungsdatei: /home/pi/.node-red/settings.js
24 Jan 11:31:48 - [info] Kontextspeicher: 'default' [ module=memory]
24 Jan 11:31:48 - [info] Benutzerverzeichnis: /home/pi/.node-red
24 Jan 11:31:48 - [warn] Projekte inaktiviert: editorTheme.projects.enabled=false
24 Jan 11:31:48 - [info] Flow-Datei: /home/pi/.node-red/flows_raspberrypi.json
24 Jan 11:31:48 - [info] Server wird jetzt auf http://127.0.0.1:1880/ ausgefĂĽhrt.
24 Jan 11:31:48 - [info] Flows starten
24 Jan 11:31:48 - [info] Flows gestartet
24 Jan 11:31:48 - [red] Uncaught Exception:
24 Jan 11:31:48 - Error: listen EACCES: permission denied 169.254.231.56:502
at Server.setupListenHandle [as _listen2] (net.js:1301:21)
at listenInCluster (net.js:1366:12)
at doListen (net.js:1503:7)
at processTicksAndRejections (internal/process/task_queues.js:81:21)
The -v is used to verify that the setcap has worked. Do it without -v first then with to check it.
As suggested, use which node to find where the executable is.
pi@raspberrypi:~ $ which node
/home/pi/.nvm/versions/node/v14.15.4/bin/node
Should i now use this path for the command? sudo setcap 'cap_net_bind_service=+ep' /home/pi/.nvm/versions/node/v14.15.4/bin/node and then sudo setcap -v 'cap_net_bind_service=+ep' /home/pi/.nvm/versions/node/v14.15.4/bin/node ?
So am I, why are you using nvm (node version manager)? I guess you didn't use the recommended method of installing node-red and nodejs on a pi.
Unless you have a good reason I suggest removing the nvm s/w, remove the .nvm folder and run the install script. That will ensure you have a consistent set of tools.
Then use which node again to check that is it using /usr/bin/node and run setcap again with that path.