Today I needed a portable version of Node-RED to do something on a machine that I don't want to install Node onto and was pretty pleased with the result I got using electron-forge.
I know others have accomplished this before but I thought this came out pretty clean so I decided to share.
Port 50820, picked by a random number generator. Changed it to not collide if already running node-red on port 1880. Ideally I'd like to find a way to customize this at launch.
Is this portable in the same sense as for example LibreOffice Portable?
That is, it does not require anything to be installed on the target machine, all components can be on a USB flash drive?
I try not to install anything on my Windows PC except the PortableApps platform.
Node-Red is installed on a Raspberry Pi but I can see uses for a USB Windows installation.
Normally done by referencing an environment variable in settings.js - see my alternate installer for examples.
You won't be able to have a single portable version that works across platforms without carring copies of the (enormous) node_modules folder. That's because Node.js allows compiled C/C++ libraries which compile to different executables on different platforms.
Not sure if this is of any use. Here is a tiny shell script that starts nr with the port number extracted from the current directory, so for example the nr directory holding the flow, settings and node_modules would be directory_name#xxxx where xxxx is the port number. If no # found then the default 1880 is used.
I also use yarn so that I can run multiple versions of node on the same host.
#!/bin/bash
###################
# start-nr.sh
# -----------
# launch node-red with the user dir as the current dir and a port.
#
# If the containing directory name ends in '#n' where n is a number
# e.g. directory-name#1880
# then the number will be used as the node-red port.
######################
nr_root=$(pwd);
default_port="1880";
port_index=`expr index "$nr_root" "#"`;
if [ "$port_index" -eq "0" ]; then
port=$default_port;
else
new_port=${nr_root:$port_index};
re='^[0-9]+$';
if ! [[ $new_port =~ $re ]] ; then
port=$default_port;
else
port=$new_port;
fi
fi
params="";
for param in "$@"
do
params+=" "$param;
done
re='admin';
if ! [[ $params =~ $re ]] ; then
cmd=$nr_root"/node_modules/.bin/node-red -u "$nr_root" -p "$port;
else
cmd=$nr_root"/node_modules/.bin/node-red"$params;
fi
#echo "cmd="$cmd;
exec $cmd
For yarn I just batch up a list of commands that I keep in 'yarn-init.sh'.
The exercise was a big part of it which is why I took care to include a walkthrough in the repo.
For me the reason not to use something like Node-RED desktop is that I now use NR for many of the things I used to use Python for (in this case translating and XML database to a flat file) where I want to make a script and throw it in a drawer until I need it again. And in this case, NR beats the pants off python since all my dependencies are portable too
I think some would preach Docker here but I have zero experience with
Yup, same problem for me when I decided to actually try installing from palette.
Luckily the solution was very simple. Node-RED was installing palette modules to the folder "./home/node_modules" and so while it was downloading the modules they weren't properly registering with NR. I changed the default settings from userDir:"home" to userDir:"." and it looks to be working now (I tested final portable file as well).
Hello @mweissen and welcome to the forums. The palette modules not working should be fixed in the v1.1.1 version, it should download the latest automatically from sourceforge. I just deleted all the old versions anyway so you should be good if you just download again.
Thanks for the quick reply. First of all: now everything works.
Yesterday I tried first the version 1.1.1, but without success. So I tried it first with the older version - with the known problems. Now I have loaded the version 1.1.1 again and everything works. Thanks again!
I plan to give a workshop on home automation to teachers in April 2022. NodeRed is an interesting tool for this. For the practical exercises, nodered-portable is a very pratical tool. I will be happy to base the exercises on it.
In this release how can I start nodered without pressing "START".
I need to automatically start nodereded (with default port-httpAdminRoot-httpNodeRoot) when operating system starts.
Optionally, the (port-httpAdminRoot-httpNodeRoot) settings in which file can be changed?
I believe that on the 'Inject' node there are options at the very bottom of the page. One of them is "inject once after X seconds" or similar....
I vaguely remember that with older version of node-red I used "npm install node-red-contrib-startup-trigger" that 'forced' the flow to ALWAYS start on deploy no matter what.
Hi
just downloaded the 1.1.1, as I'm starting to learn node red.
Unfortunately I can't find the menu item Palette to get new nodes, but in all the pictures here in the post I can see the item is there....
Do i something wrong?
Thanks
Andrea