# (Solved) How to able Node-Red to create files and folders on DietPi

**URL:** <https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973>\
**Category:** General\
**Created:** [17 November 2018 17:10 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973 "2018-11-17T17:10:31Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 17:10 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/1 "2018-11-17T17:10:31Z")

</div>

Hi all.  
I'm getting this permission error when trying to save data as a file:  
failed to create file: Error: EACCES: permission denied, mkdir ...  
I solve it by creating myself the directories and the file and given permission for all for the file with the following command:  
chmod a=rwx "filename"﻿  
That's should help someone with the same problem but I would like to know how can I auto start the service with the root privileges so Red-Node can create the directories and file.  
I'm new to linux and couldn't find how to do it on Google.  
thanks for any help.

---

<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:** [17 November 2018 17:25 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/2 "2018-11-17T17:25:07Z")

</div>

Have you installed using the recommended bash script from [1]?  
If so then it will have installed a systemd service which you can enable with  
sudo systemctl enable nodered  
Then it will autostart on boot.

[1] [https://nodered.org/docs/hardware/raspberrypi](https://nodered.org/docs/hardware/raspberrypi)

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 17:33 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/3 "2018-11-17T17:33:42Z")

</div>

Hi, Colin.  
Thanks for the fast answer.  
No, I have installed it using the optimized software list from DietPi.  
When I tried that command I get:  
Failed to enable unit: File nodered.service: No such file or directory.  
Is there any commands to autostart it with sudo or should I uninstall and install using the recommended bash script you suggest?

---

<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:** [17 November 2018 17:39 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/4 "2018-11-17T17:39:56Z")

</div>

> [@Shark\_Polo](#):
>
> Failed to enable unit: File nodered.service: No such file or directory.

That is because you have not run the script, which provides the systemd service file. If you look on the page I linked to it says it is compatible with DietPi so I suggest you run the script.

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 17:55 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/5 "2018-11-17T17:55:35Z")

</div>

I ran the bash script and get the following message:  
Diet-Pi detected - only going to add the node-red-start, -stop, -log commands.  
The node-red still has no permission to create a folder or file.  
What can I do?

---

<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:** [17 November 2018 18:44 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/6 "2018-11-17T18:44:59Z")

</div>

Does the systemctl enable command now work?

---

<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:** [17 November 2018 18:47 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/7 "2018-11-17T18:47:58Z")

</div>

DietPi seems to have its own software installer and its own process controller.

[https://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=5393#p5393](https://dietpi.com/phpbb/viewtopic.php?f=8&t=5&p=5393#p5393)

I would say that you will need to raise an issue in their forums if their Node-RED installation doesn't work.

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 19:12 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/8 "2018-11-17T19:12:58Z")

</div>

It does not.  
Failed to enable unit: File nodered.service: No such file or directory

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [17 November 2018 19:15 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/9 "2018-11-17T19:15:45Z")

</div>

Then look further down that page where there are instructions on how to install them separately

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 19:34 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/10 "2018-11-17T19:34:04Z")

</div>

After installing separately, now the command "sudo systemctl enable nodered.service" runs with no error or message saying ok but Red-Node still note able to create a folder or file.

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 19:34 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/11 "2018-11-17T19:34:58Z")

</div>

Ok, I will try that too.

---

<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:** [17 November 2018 19:56 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/12 "2018-11-17T19:56:43Z")

</div>

To clarify.... Diet-PI have their own way of installing Node-RED so the recommended way to install and upgrade it is by using their software installer. All our script does is add some aliases to their start and stop commands so you can use node-red-start and node-red-stop.

On their install to start node-red their command is `dietpi-services node-red start` etc

to set it to start at boot I think you can use `dietpi-services enable node-red`  
(but I don't have a DietPI build handy so you would have to read their docs).

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 20:04 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/13 "2018-11-17T20:04:26Z")

</div>

Just to be clear, what I want is start Red-Node with sudo privileges so it can create folder and file.  
I thought it would be a simple command line but it seems very complicated if possible.

---

<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:** [17 November 2018 20:11 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/14 "2018-11-17T20:11:16Z")

</div>

You need to find the node-red.service file and within that there should be lines like  
User=pi and Group=pi which you can change to root and then stop and restart the service.

---

<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:** [17 November 2018 20:49 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/15 "2018-11-17T20:49:55Z")

</div>

> [@Shark\_Polo](#):
>
> Just to be clear, what I want is start Red-Node with sudo privileges so it can create folder and file.

It is potentially dangerous to run node-red as root as a problem with a node or the flow could trash your system. Can you not give the user pi write access to the areas you want to write?

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 21:17 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/16 "2018-11-17T21:17:03Z")

</div>

Yes, I can and I did.  
This is the solution that I found and posted here on this topic if someone else search for.  
But it would be most practical if Node-Red could create.

---

<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:** [17 November 2018 21:30 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/17 "2018-11-17T21:30:41Z")

</div>

We do not control how the DietPi project wish to run Node-RED, and configure access. On any Linux system it is generally safer not to allow free access to everywhere - and it is up to the administrator to grant access.

It see like they run Node-RED to run as a user nodered - so it's up to you to give that user access to wherever you want - or indeed add that user to the admin/root group. Up to you.

---

<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:** [17 November 2018 21:36 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/18 "2018-11-17T21:36:02Z")

</div>

Which files/directories was it that it could not create?

---

<div class="post-metadata">

**Author:** ![Shark\_Polo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shark_polo/32/3833_2.png) [@Shark\_Polo](https://discourse.nodered.org/u/Shark_Polo)\
**Post date:** [17 November 2018 23:11 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/19 "2018-11-17T23:11:59Z")

</div>

I used the node file to create a txt file storing the variables from a MQTT subscription.

---

<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:** [18 November 2018 07:04 UTC](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973/20 "2018-11-18T07:04:41Z")

</div>

What folder were you creating it in?

[Next page](https://discourse.nodered.org/t/solved-how-to-able-node-red-to-create-files-and-folders-on-dietpi/4973.md?page=2)
