Advice setting up node-red for a class

Here's the basic problem

  1. I want to use node-red in a cs course
  2. The students will likely work on multiple machines and multiple plaforms (lab, their own, etc)
  3. The students will each have one git repo for the course
  4. I'd like them to keep the flows they develop as separate projects, but within the one repo.

Here are some alternatives:

  1. create a separate data directory for each lab and execute
    node-red --userData "labdatadirectory"

  2. use alternate-node-installer to create a repo specific instance of node-red, with a separate data
    directory for each project. The default script is hardwired to use .data, but I could modify the script for each experiment

  3. use the node-red projects feature. This seems problematic because it creates a separate git repo for each project and there doesn't seem to be a way to use a single repo for all projects.

It seems (1) is easiest for me. (2) provides some guarantee that a consistent version of node-red is used throughout the course. Are there issues across platforms (os x/windows/linux ?). (3) seems a non-starter unless there is a good way to deal with the per project repo.

I'd welcome comments/suggestions/whatever


I would say that 2 is probably the safest overall and, as you say, will avoid issues of versioning. It also helps avoid permissions issues since no admin-level access is required on any device/OS type.

However, it is slightly more complex to explain - so it may somewhat depend on the level of capability of your students.

The alternate-node-installer script could be amended to include an optional parameter for the data folder and even to initialise git in the data folder. I'd be delighted to take a PR for that.

One small thing to note, it is best to make Node-RED use the "pretty" layout for the flows file if you want to use git as it makes diff's a lot easier to follow and makes it easier on git. You have to set something in the settings.js file which again could be done using the installer script.

The other thing to note is that the alt. installer doesn't try to install node.js/npm so students will need to do that themselves unless you have another script. Personally, I would get students to do that themselves as a pre-requisite if you can as it will help their understanding.

In regard to using Node-RED's projects feature, personally I wouldn't use that in this instance because of the complexity it adds to the folder layout and the potential for issues regarding encryption.

Just my personal thoughts.

Thanks for the speedy reply ! Here a few more thoughts on pursuing option (2)

We generally create a "template" repo for the class which the students fork and then use for their assignments rather than a repo per assignment

I imagine something like the following for the template.. Roughly, a single
set of node-red modules (pre-installed in the template), and, for each lab, a customized data
directory with the package.json "pointing" to the current data directory and the node-red modules.

> /- 
>  |  node-modules/
>  |  Labs/
>             |   lab1/
>                     |
>                     | nodered-data/
>                                  | package.json
>                                  | settings.js
>                                  | lib
>              |  lab2/
>                    (similar to lab1)

One thing I don't understand is how the absolute paths that node-red creates in .config.json work out when cloning and using a repo on multiple machines.

The layout looks OK, you would simply need a script to restart node-red with a different data folder.

One thing that you can do if you want nodes pre-installed is to install them at the master folder level (e.g. the same level as Node-RED itself if you are using my alt. installer). This works well and avoids any mishaps from students trying to use the palette manager to mess with installed nodes. It still allows them to install other nodes just not to uninstall (or update) the ones you specify.

That way, the absolute path would be known. You would still need to have a script that used a master package.json and did an npm install then amended the .config.json files for each lab. The lab-level package.json would then be just standard.

Again, the alt. installer script could be amended to handle this.

Thank you ! I like the idea of some pre-installed nodes -- especially for initial experiments.

There's still something I don't fully understand about the .config.json files. For example, in my limited experiment, the nodes are defined with an absolute file path, e.g.

"file": "/home/geobrown/Teaching/po181u/mynodered/node_modules/@node-red/nodes/core/common/20-inject.js"

If the students clone the directory, then this would point to the wrong place. Are you suggesting a script is needed to "patch" this path for each lab after it is cloned ?


Yes, I'm afraid so. Also note that the problem is worse if allowing your course to be run on different OS's

"file": "C:\\src\\nr\\node_modules\\@node-red\\nodes\\core\\network\\21-httprequest.js"

is what shows up on my dev PC for example.

Thankfully, such manipulations are easy to do even cross-platform by using a node.js command-line script as you will see in the bin folder for the alt. installer. Using npm allows us to run such scripts correctly on any platform supported by node.js.

That's bit of a downer -- not because a script is too hard to write, but getting students to run it in each environment is. Especially if they move between machines ! I may just have to force the students to work on school machines -- queue the whining soundtrack. At least the paths will work even if they move between machines of the same flavor.

On a side note, my working life is in github repositories and I routinely move between OS X and linux happily pushing and pulling as I go. I don't think that model will translate well for node-red.


Well, you can make it part of the marking for the assignments :wink:

I think that you would most likely create a single master repo that uses the alt. installer and runs the script. Publish that to npm or make them install it from GitHub and it should do everything for them.

Are these students supposed to be IT literate? Are they Comp Sci students? What age group are they? If they are high-school or above and doing comp sci then they really should be able to run a script that sets things up for them.

There are still some rough edges to Node-RED it is true. But if the likes of us don't try to find creative ways to improve things, nobody else will - or at least progress will be glacial.

I'd be happy to help if it improves things for others.

1 Like

Thanks for all your help so far ! I think I'll go the easiest route next semester and have them use lab machines -- there are enough moving parts to get to work together -- but with node-red installed in their repos (the directory structure I suggested above).

One of the issues is I don't know what the background of the students will be -- I'll be a visiting faculty in the spring. The certainly will have had two CS classes -- an intro and data structures (in java), but probably little command line experience and relatively light git experience. node-red is just a piece of a larger software pie, so too many glitches would be painful (for all involved).

I'm new to code-red myself, but I wanted something that the students could use relatively easily to test in an IoT environment -- talking to an mqtt broker, talking to a "device" through a serial port, building a dashboard, etc.

I think what you have shown me so far and the scripts you have developed are probably enough to go with for now. So, once again, thanks !


1 Like

One thing that occurred to me when I was thinking about how the alt. installer could be improved, you actually don't need to adjust the .config.json file - Node-RED does that itself, you only need to npm install the nodes.

So that simplifies the installation. I've added a todo file to the alt. installer on GitHub that outlines some ideas.

Also, didn't spot this yesterday, they wouldn't clone the directory but rather would npm install from your GitHub master repo. That lets you control the installation process using node.js so all they need is npm install <githuburl>. You could publish to npm as well of course if you wanted to.