Shared system folders in multi user instances?


I tested multi users by running more than one nodered instances in the same machine, same flow for each.

I want to know if it is possible to share from the main nodered admin folder, for exemple "node-modules" and ".npm" folder witch take both a lot of disk space ?

I have read the settings.js, and i can't see any option for that.

Thanks :wink:

Lots of ways you could approach this. You should do some background reading on how node.js and npm works.

Obviously all instances of node-red can use the same master package. And you will find that, if you do manual installs rather using the "Manage palette" menu, you can install nodes at the same level as node-red itself. Personally, I find this easier when doing local installs rather than global. If you install node-red into a folder (as is common for many node.js applications), you can install nodes into the same folder. Then run multiple instances from that install. Of course, users would not be able to uninstall those nodes.

You could also share the node_modules folder from a userDir folder as well. However, everyone who had access to the folder could install/uninstall to/from it which wouldn't be very safe. In addition, the instances that hadn't done the install would need some separate process to update their package.json files. That is avoided if you install to the parent node-red level, all that is needed is to restart each instance.


As you say, global install or local install... Everytime i create a new user, i need to install nodered for this user, locally ?
Do you think i can make a symbolic link from a home user that point to node_modules ? That all ?

Here is how i see that, globaly i would want to build a linux script to create a user :

Consider i have a shared_user_folder:

  • Create a new user
  • install node-red
  • copy the application flow (and eventualy settings.js) in the .nodered folder
  • Create a link that point to the main user folder /shared_user_folder/node_module

That a good way ?

Not if you use a global install. Then they will all use the same node-red and global node_modules. Of course then you cannot have different versions of node red for different users.

Sorry, i'm confused.

I must to do global install of nodered to use linked /node_modules technic from each nodered home user ?

I have read this. If i understand, @TotallyInformation make a local install to launch more than one node red instance ?
A few days ago, (i installed node red localy on a VM from the classic NR precedure), i created a new user, copy all the original .nodered folder into the new home user. And start a new instance with another port. That is running now, but is it proper ?

No, not at all. By locally, I mean not using the -g option when installing Node-RED. You will install to a standard folder which should be read-only accessible to all users needing to use Node-RED. Each user then has a separate userDir folder that is passed as a parameter to the Node-RED startup for that user.

So, you have an OS user/group for installing Node-RED and separate OS users for each instance. The consuming users need read/execute access to the Node-RED installation folder. But they don't need write access.

Then you can install nodes common to all users in the Node-RED folder and users can't mess with those.

Users can, however, install/uninstall their own nodes as well. If you want to stop that, a different approach is required to prevent the users from accessing their userDir folders directly. That is possible but more complex.

You don't actually need that and should avoid it if possible because it leaves you back with the problem of disjointed restarts for each user and would let users install/remove nodes for everyone which is almost certainly not what you want.

Ok that it's clear for me.

I propose this, only for the /node_modules. If i put it in any admin forlder, shared for all users created. And apply to it only read and execute atribute ?
Also, i will disable the node red interface for users and enable their login/mp in settings.js file.

You don't need to do that. Node-RED happily consumes nodes installed along-side Node-RED itself. So no need to mess with sharing a folder.

So ! I create a user with /home/user/.nodered directory, i copy settings.js and other config json files to it (without /node_modules), i launch node-red command with this path in argument and that all ?


I tryed this :

  • First :

I created a new linux user "test", a /.nodered folder and copyed to it minimal files without /node_modules. Port 1881 in settings.js.
I started instance for this user by : sudo node-red -u /home/test/.nodered

A warning said me that many node missing.

Then i created a link that point to the original node_modules in my nodered home :
sudo ln -s /home/me/.nodered/nodes_modules

That is running well.

  • Second :

I created another nodered folder in my user home named .nodered2 without /node_modules.
Port 1882 in settings.js.

It's the same problem, i must to create another symbolic link to /.nodered/node_modules
and this third instance fonction properly.

  1. Make sure that you have Node.js installed.
  2. Create a new user nodered.
  3. switch to that user id and create a convenient folder: nodered
  4. in that new folder npm install node-red --production --unsafe-perm
  5. Change the permissions on the nodered folder so that the nodered group only has read and execute permissions.
  6. Create a new user fred
  7. add user fred to group nodered
  8. Create a bash script in fred's home location that runs node-red - something like node /home/nodered/nodered/node_modules/node-red/red.js
  9. run the script to set up the fred users .node-red folder and files then stop node-red
  10. Go install some new nodes as user nodered into the ~/nodered folder for that user.
  11. Switch back to fred and restart node-red.

Actually, in step 9, once fred has a ~/.node-red folder, you can add the startup for node-red to that folder's package.json file and you won't need the bash script so you could in fact skip step 8 and just run node-red manually the first time.

Of course, once you have a single user's ~/,node-red folder, you can take a copy and deploy that direct to any new users and so miss out the rest of the steps. Maybe keep a copy in the nodered users home and create a deployment script there.

Note that I've not done this myself and I've not tested these steps but it should be about right.

Thanls for this procedure.

The idea with that, we create only one path with one node_modules and all users in the same nodered group access to it with r and x permissions ... that's ok !

I will try it.

But with what i've done, at the end is it the same ? if i apply same permissions ?

Mmmm the problem is, when i put this install command, only node_modules & package.json is copied in the /nodered folder...
And when i try to start from /home/fred/.nodered he say me :frowning:

VirtualBox:/home/fred/.node-red$ node-red-start

Node-RED is not yet fully installed. Please re-run the install script again manually.
   bash <(curl -sL
then retry  node-red-start

Need to install nodered normaly in addition ?

Sorry, I thought you understood that you have to start node-red manually, you can't use the node-red-start command. Something like node node_modules/node-red/red.js

I put it as the start script in the package.json file and then you only have to do npm start.

I'm sorry, i thing i'm arriving to my linux/nodered
knowledge limits, and to take you to much time ...

This what i've done :

// install Node.js

// Create a new user "wbsys" and his personnal folder
sudo useradd -m wbsys

// switch to that user id and create a convenient folder in /home/wbsys "/nodered"
su wbsys
cd /home/wbsys
sudo mkdir nodered

// go in "/nodered" folder and install nodered
cd /nodered
sudo npm install node-red --production --unsafe-perm

// verify or change "/nodered" permission with read and execute only
sudo chmod 755 nodered

// create a new group "nodered"
sudo groupadd nodered

// put "/nodered" folder to "nodered" group
sudo chgrp -R nodered /home/wbsys/nodered

// Create a first user "fred", his personnal folder and password
sudo useradd -m fred
sudo passwd fred

// add "fred" user to the "nodered" group
sudo gpasswd -a fred nodered

I've created /.node-red in fred folder, and put a minimalist package.json and settings.js files into it.

But now, i don't understand how all of that run.
In this example, i ran start in a bash like this (.sh in fred home folder :

echo "ok"

Nodered response :

fred@sylvain-VirtualBox:~$ ./
11 Feb 11:49:24 - [error] Failed to start server:
11 Feb 11:49:24 - [error] Error: EACCES: permission denied, mkdir '/home/fred/.node-red/node_modules'

I don't understand how nodered can reach /wbsys/nodered/node_modules even if fred is in the nodered group.

Here my /etc/group :



As user fred, run node /home/wbsys/nodered/node_modules/node-red/red.js manually 1 time, that should update the package.json and create all of the other files needed. And add that command as the "start" script to the package.json file in fred's ~/.node-red folder. Then to start node-red for fred in the future, cd ~/.node-red && npm start. Your other script is OK, it just needs the node at the start to tell node.js to start the actual red.js script. You could, of course, instead change the #! line to reference your installation of node.js, then you wouldn't need the leading node .

You didn't apply the permissions change to sub-folders when you changed them.

I think, perhaps, that i see the end of the tunnel...

I had this error :

fred@sylvain-VirtualBox:~/.node-red$ node /home/wbsys/nodered/node_modules/node-red/red.js
    throw err;

Error: EACCES: permission denied, copyfile '/home/wbsys/nodered/node_modules/node-red/settings.js' -> '/home/fred/.node-red/settings.js'
    at Object.copyFileSync (fs.js:2061:3)
    at copyFile (/home/wbsys/nodered/node_modules/fs-extra/lib/copy-sync/copy-sync.js:70:6)
    at onFile (/home/wbsys/nodered/node_modules/fs-extra/lib/copy-sync/copy-sync.js:56:25)
    at getStats (/home/wbsys/nodered/node_modules/fs-extra/lib/copy-sync/copy-sync.js:48:44)
    at handleFilterAndCopy (/home/wbsys/nodered/node_modules/fs-extra/lib/copy-sync/copy-sync.js:33:10)
    at Object.copySync (/home/wbsys/nodered/node_modules/fs-extra/lib/copy-sync/copy-sync.js:26:10)
    at Object.<anonymous> (/home/wbsys/nodered/node_modules/node-red/red.js:125:20)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32) {
  errno: -13,
  syscall: 'copyfile',
  code: 'EACCES',
  path: '/home/wbsys/nodered/node_modules/node-red/settings.js',
  dest: '/home/fred/.node-red/settings.js'

Fix it with
wbsys@sylvain-VirtualBox:/home/fred$ sudo chmod 777 .node-red/

YES ! node-red started with your command :
node /home/wbsys/nodered/node_modules/node-red/red.js

Welcome to Node-RED

11 Feb 14:20:57 - [info] Node-RED version: v2.2.0
11 Feb 14:20:57 - [info] Node.js  version: v14.19.0
11 Feb 14:20:57 - [info] Linux 5.4.0-99-generic x64 LE
11 Feb 14:20:58 - [info] Loading palette nodes
11 Feb 14:20:59 - [info] Settings file  : /home/fred/.node-red/settings.js
11 Feb 14:20:59 - [info] Context store  : 'default' [module=memory]
11 Feb 14:20:59 - [info] User directory : /home/fred/.node-red
11 Feb 14:20:59 - [warn] Projects disabled : editorTheme.projects.enabled=false
11 Feb 14:20:59 - [info] Flows file     : /home/fred/.node-red/flows.json
11 Feb 14:20:59 - [info] Creating new flow file
11 Feb 14:20:59 - [warn] 


11 Feb 14:20:59 - [info] Server now running at
11 Feb 14:20:59 - [info] Starting flows
11 Feb 14:20:59 - [info] Started flows

I have these new files in .node-red as you said, and node_module is empty so, i suppose all is running, the "link" from fred is effective ??

Mmmm... but when i use the palete for install the dashboard, node_modules in fred get the dashboard installation...