Portable Node-RED v2.1.3

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'.

yarn add node@14.17.5
yarn add node-red@2.1.3
yarn add node-red-dashboard@3.1.0
1 Like