Running Node.js need be root

I want to write a node with a node.js library. but the js library must run in "root mode".
Can i include ths library into node-red ? How to if i can do it ? :thinking:

What library is that?

when i run with node.js. I must be root(sudo node xxxx).

You should not need to be root to use that, you need to make sure that the node red user has access to the hardware. Are you getting an error when you use it?

@colin. Actually the docs say you need to be root. That is the reason I dont use it for the default gpio nodes. We do have the pigpiod version node that uses a network connection to the pigpio daemon (that does run as root)

I forgot if there is any message. I will try again. I need sudo command when i use node calling it and it can access GPIO.

OK, I missed that. But whatever they say, provided the user has access to the hardware or appropriate directories, I would not have expected a problem. Unless the code has a specific check on root which would be a bit odd. Perhaps there is something more subtle going on though.

@jinyistudio can you not use the pigpiod node

See this response from the author fivdi ...

That's poor, unless there really is a reason for it.

You can run Node-RED as root user so I'd suggest doing that and then try building the simple node as root user and see if that works

if it does, and I don't see why it shouldn't, then you should be fine to make your node.

Obviously, your node will not work for other people running Node-RED normally

1 Like

Yes, I can use pi-gpiod. I want to drive GPIO directly. because i want to use SPI. :joy:

Indeed - while it's not good practise to run as root - sometimes it is the only way to proceed, and as long as you are aware of the risks - usually small as long as access from the internet is not involved - then there shouldn't be a problem.

As @cymplecy points out if anyone else want to do the same they would also need to be aware of the limitations.

But I would also suggest looking at the pigpiod daemon as that doesn't have this issue - but may not be suitable for other reasons of course.

To be honest, library developers saying to run as root, 99% of the time is laziness or lack of understanding.

These articles may give some ideas as to how to set the permissions correctly:

(I didn't really check them in detail though).

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.