# Running Node.js need be root

**URL:** <https://discourse.nodered.org/t/running-node-js-need-be-root/32522>\
**Category:** General\
**Created:** [7 September 2020 02:18 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522 "2020-09-07T02:18:02Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jinyistudio/32/23670_2.png) [@jinyistudio](https://discourse.nodered.org/u/jinyistudio)\
**Post date:** [7 September 2020 02:18 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/1 "2020-09-07T02:18:02Z")

</div>

Hi  
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 ? 🤔

---

<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:** [7 September 2020 06:09 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/2 "2020-09-07T06:09:49Z")

</div>

What library is that?

---

<div class="post-metadata">

**Author:** ![jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jinyistudio/32/23670_2.png) [@jinyistudio](https://discourse.nodered.org/u/jinyistudio)\
**Post date:** [7 September 2020 06:35 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/3 "2020-09-07T06:35:26Z")

</div>

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

> **[fivdi/pigpio](https://github.com/fivdi/pigpio)**
>
> Fast GPIO, PWM, servo control, state change notification and interrupt handling with Node.js on the Raspberry Pi - fivdi/pigpio

---

<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:** [7 September 2020 06:51 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/4 "2020-09-07T06:51:53Z")

</div>

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?

---

<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:** [7 September 2020 07:04 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/5 "2020-09-07T07:04:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jinyistudio/32/23670_2.png) [@jinyistudio](https://discourse.nodered.org/u/jinyistudio)\
**Post date:** [7 September 2020 07:12 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/6 "2020-09-07T07:12:56Z")

</div>

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.

---

<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:** [7 September 2020 08:23 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/7 "2020-09-07T08:23:53Z")

</div>

> [@dceejay](#):
>
> the docs say you need to be root

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 [node-red-node-pi-gpiod (node) - Node-RED](https://flows.nodered.org/node/node-red-node-pi-gpiod)?

---

<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:** [7 September 2020 08:28 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/8 "2020-09-07T08:28:50Z")

</div>

See this response from the author fivdi ...

> <https://github.com/fivdi/pigpio/issues/2#issuecomment-170687768>
>
> 2015-12-11 15:36:28 initCheckPermitted: 
> +---------------------------------------------------------+
> |Sorry, you don't have permission to run this program. |
> |Try running as root, e.g. precede the command with...

---

<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:** [7 September 2020 08:35 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/9 "2020-09-07T08:35:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![cymplecy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/cymplecy/32/2773_2.png) [@cymplecy](https://discourse.nodered.org/u/cymplecy)\
**Post date:** [7 September 2020 08:37 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/10 "2020-09-07T08:37:28Z")

</div>

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

[https://nodered.org/docs/creating-nodes/first-node](https://nodered.org/docs/creating-nodes/first-node)

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

---

<div class="post-metadata">

**Author:** ![jinyistudio](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jinyistudio/32/23670_2.png) [@jinyistudio](https://discourse.nodered.org/u/jinyistudio)\
**Post date:** [7 September 2020 08:59 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/11 "2020-09-07T08:59:02Z")

</div>

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

---

<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:** [7 September 2020 09:04 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/12 "2020-09-07T09:04:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [7 September 2020 22:28 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/13 "2020-09-07T22:28:31Z")

</div>

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:

- [https://roboticsbackend.com/raspberry-pi-hardware-permissions/](https://roboticsbackend.com/raspberry-pi-hardware-permissions/)
- [https://www.element14.com/community/thread/19995/l/anyone-know-how-to-access-raspi-gpio-without-sudo](https://www.element14.com/community/thread/19995/l/anyone-know-how-to-access-raspi-gpio-without-sudo)

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [6 November 2020 22:28 UTC](https://discourse.nodered.org/t/running-node-js-need-be-root/32522/14 "2020-11-06T22:28:39Z")

</div>

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