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
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
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.
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.
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 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.
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.
switch to that user id and create a convenient folder: nodered
in that new folder npm install node-red --production --unsafe-perm
Change the permissions on the nodered folder so that the nodered group only has read and execute permissions.
Create a new user fred
add user fred to group nodered
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
run the script to set up the fred users .node-red folder and files then stop node-red
Go install some new nodes as user nodered into the ~/nodered folder for that user.
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.
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
Node-RED is not yet fully installed. Please re-run the install script again manually.
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
then retry node-red-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"
sudo mkdir nodered
// go in "/nodered" folder and install 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 :
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 .