The default install installs node-red globally using the -g switch and is the most common installation method.
However if you are working on multiple projects and you need to keep them separate then there are a number of things you can do:
- Use Separate Flow files
- Use Different user directories
- Use a Local Install
Use Separate Flow Files
Using the global install we can make each project use its own flow file.
This we can do by setting the flow file in the settings.js file but a much easier and flexible method is to pass the flow file name on the command line.
notice there is no switch.
Because we often want to have access to multiple projects at the same time we normally start them on a different port using:
node-red testflow.json -p 1881
Very easy to do and doesn’t require any settings changes.
1. All flows share the same node_modules folder so if a flow requires that you install a new module it is available to all flows.
2. Updating node-red updates node-red for all flows as the install is global.
Use Different User Directories
Instead of all flows using the .node-red folder we can store flows, and also new modules in a separate folder by using user directories.
Again we can do this by editing the settings file. The default is .node-red.
or by using the -u switch on the command line which is much easier.
node-red -u user1
This causes node-red to create a folder called user1 and copy config files into it. In addition any nodes we install are placed into this folder under a node_modules folder.
Again because we often want to have access to multiple projects at the same time we normally start them on a different port using:
node-red -u user1 -p 1881
1. Very easy to do and doesn’t require any settings changes.
2. The node_modules folder is created in this folder contains any node installed into this flow you install a new module it is available to all flows started from this folder..
3. The flow file is also created inside the user folder.
4. The user folder contains a package.json file with the module dependencies for this flow.
1. Updating node-red updates node-red for all flows in all flowfiles as the node-red install is global.
Note: this is my preferred method.
Use a Local Install
Generally node projects use local installs, and so this is the method used by many node.js developers.
It is a little more difficult to setup than the two previous methods but does mean that all of the projects are self contained.
To create a local install you first create the project folder and then go to the folder and run
npm install node-red
This will install node-red in the node_modules folder inside the projects folder.
The problem with this install is that it is not set to auto start on boot and the node-red shortcut isn’t created.
You can create the shortcut manually using:
ln -s node_modules/nod-red/bin/red.js node-red>/pre>
Projects are completely separate and you can use different versions of node-red on different projects.
More difficult to set up initially
If you are working on multiple projects there are several techniques you can use to keep them separate.
They vary in the degree of separation that is achieved and the complexity in doing so.
My preferred method is using separate user directories.
Note: Projects Feature
In version 0.18 node-red introduced the projects feature. It is disabled by default but can be enabled in the settings.js file.
This feature makes your project available over Github and I do not cover it here as most people will not use it.
You can find more about this feature here.
Related Tutorials and Resources: