Settings.js moved to root

Can anyone help please
I have been backing up my node-red flows regularly, but something strange has changed and my backup files are now being ignored. I deleted settings.js and it is not being re-created.
Does this mean it has moved to root? I don't know how to recover.

4 Feb 10:20:14 - [info] Node-RED version: v1.0.3
4 Feb 10:20:14 - [info] Node.js version: v12.14.1
4 Feb 10:20:14 - [info] Linux 4.19.93-v7+ arm LE
4 Feb 10:20:16 - [info] Loading palette nodes
4 Feb 10:20:20 - [info] Settings file : /root/.node-red/settings.js
4 Feb 10:20:20 - [info] Context store : 'default' [module=memory]
4 Feb 10:20:20 - [info] User directory : /root/.node-red
4 Feb 10:20:20 - [warn] Projects disabled : editorTheme.projects.enabled=false
4 Feb 10:20:20 - [info] Flows file : /root/.node-red/flows_atticPI.json

Looks like you are executing as root which is strongly discouraged. That's why it is picking up root's settings file as shown in your listing.

Thanks but as a Linux noob I don't know how that has happened. I followed the installation instructions carefully.

Which install instructions did you follow (provide link please) and how are you starting node-red?

I think it was
https://nodered.org/docs/getting-started/raspberrypi
and I start node red automatically as a service.

Apologies... I think I am being stupid. I was stop/starting node red with
sudo node-red-stop/sudo node-red-start
Would that explain why settings.js was regenerating in a different place after I had deleted from its usual folder?
Sorry linux and root etc confuses me.

1 Like

Yes, when you start node red it looks for a .node-red folder in the current users home directory. When you use sudo the current user effectively becomes the root user so it looks there instead of in your own directory.

[Edit] Don't worry about the confusion, once you get the hang of it you will find it a lot less confusing than Windows.

Yes, you've confused the normal manual startup with the setup for running Node-RED as a service.

Take the sudo off and you should get back to your normal settings.js and flows. Though you might also want to delete the root .node-red folder so that you don't have confusion in the future.

In case it isn't clear (apologies if I'm over explaining), you need sudo when setting up the service because that is a change to the system and so you need administrative rights and sudo makes you temporarily the root user of course. But you don't want that for a normal startup as it is a risk to the system if something goes wrong (a Node-RED flow could delete parts of your system for example).

Confusion over these things is far from uncommon, we've all been there so as Colin say's it isn't a problem.

Thank you for your help. I think I am up and running again.

I assume that I now have some stuff in the root folder. I can’t seem to find it to delete.

The root folder is not accessible to normal uses. This should do it
sudo rm -rf /root/.node-red
Make absolutely certain that there are not any spaces in /root/.node-red. If, for example, you did (and I am not even going to write it in full here in case someone copies it) the rm -rf command followed by / .node-red then that would first remove (without warning) the / directory and all directories under it, which it could do since it is running using sudo. That would leave you with an empty SD card or disc, which is not helpful.
Normally when removing folders using rm -rf , with or without sudo. I would recommend switching to the parent directory first, then using rm without the path, so in this case

cd /root
sudo rm -rf .node-red

obviously checking that the cd has worked before running the rm command. In this case you (probably) can't do that as /root is not normally accessible at all to normal users, so the cd would fail. If you did not notice that the cd had failed then it would remove your own .node-red directory which equally is not a good thing. The moral is always be extremely careful when using rm -rf that you are removing the right directory.

Alternatively, you could assume root privileges and delete it...

sudo su 
cd
ls -la
rm -rf .node-red
exit

root

I tend not to recommend the use of sudo su. It is even more dangerous for the uninitiated as it is easy to forget to exit from the su session and carry on regardless, with even more risk of damaging something accidentally.

Same here, but for something as trivial and quick as this, I'd like to think that the OP would remember :wink:

1 Like

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