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

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.

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

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?

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.

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?

Does the systemctl enable command now work?

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


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

1 Like

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

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


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.

Ok, I will try that too.

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

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.

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.

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?

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.

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.

1 Like

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

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

What folder were you creating it in?

1 Like