Amending settings.js file after NR update

Has anyone found an easy way to update their settings.js file after updating their Node-RED version?

I always try to keep my settings file as close to the current default settings file as possible, to ensure that any new features added would be available to me, but it's a PITA on a small laptop copying and pasting sections in, and I usually end up then spending time sorting out where I've missed a comma, or inserted in the wrong section.... urgh!
...and compounded when there a number of instances to update.

I'm aware that I can run the diff cmd -
diff -y --suppress-common-lines /usr/lib/node_modules/node-red/settings.js /home/pi/.node-red/settings.js
but it's help is limited, and it also highlights sections when data has been previously changed, like 'adminAuth' - credentials etc.

There must be an easier way.

I'm afraid that my default settings file is a little different to the default. Though Nick did add some of my commenting suggestions to a previous update of the default.

I use VScode to show a visual diff of the two in order to work out what might have changed. If I get desperate (rare these days since big changes to the settings are rare now), I would grab a version from the previous release and compare that with the new release then update my own from that.

So easy? Not really. :grinning:

But VScode makes with eslint makes things very much easier and helps avoids the silly issues with comma's that we all make. Hint: I ALWAYS include trailing commas, it greatly reduces the issues.

2 Likes

I'll be honest, I don't make a lot of changes to the defaults - unless they allow some undesired ability/behaviours.

I'm pretty laxed on the defaults, other then the defaults for secure access.

1 Like

I use a shell script to make my customisations of settings.js (and flows.json) so if I reinstall I can delete settings.js and use the script to reapply the changes.

The settings.js part of it:


############################################
DIR=/home/pi/.node-red

# Uses gawk. Probably not needed but a useful catch before running on an unknown system
gawk -V >/dev/null || { echo Please install gawk; exit 1; }
# Does /home/pi/bin/ipaddress exist?
IP=/home/pi/bin/ipaddress
test -x $IP || { echo "This program needs (missing) $IP - quitting." ; exit 1; } # {} groups commands, need ; after last command.

checkfile()
{
  file=$1; string=$2
  if test ! -f $file
  then
     echo $file not found; return 1
  elif grep $string $file >/dev/null
  then
     echo $string is already in $file - Not changed
     return 1
  fi
}

echo "=============================================== settings.js ..." # 2 insertions, above module.exports and below editorTheme
FILE=$DIR/settings.js
checkfile $FILE "process.env.HOSTNAME" || exit 1
cp $FILE $FILE.bak || exit 1
gawk ' { if ($0 ~ /^module.exports =/) {
                                          print "// ----------- added by script ----------"
                                          print " hostname = require('\''os'\'').hostname();"
                                          print " const execSync = require('\''child_process'\'').execSync;"
                                          print " const ipaddress = execSync('\''/home/pi/bin/ipaddress'\'', { encoding: '\''utf-8'\'' });"
                                          print " device = hostname + '\'' '\'' + ipaddress;"
                                          print " process.env.HOSTNAME = hostname;"
                                          print " process.env.DEVICE = device;"
                                          print "// --------------------------------------"
                                          print
                                      }
        else if ($0 ~ /editorTheme: {/) {
                                          print
                                          print "// ----------- added by script ----------"
                                          print "       header: {"
                                          print "          title: process.env.DEVICE"
                                          print "       },"
                                          print "       page: {"
                                          print "          title: process.env.DEVICE,"
                                          print "          css: \"/home/pi/.node-red/editor.css\""
                                          print "       },"
                                          print "// --------------------------------------"
                                      }
        else print
      }' $FILE > $FILE.tmp
echo $FILE was changed. Original saved as $FILE.bak
echo
mv $FILE.tmp $FILE || exit 1

Yes, but that is just adding features that you are already aware of.
I'm wishing to add features that are introduced when a new Node-RED version is released.

I offsite backup my settings, so restoring them isn't an issue.

I think on balance, if I were going to try and automate, I would maintain version-specific copies on each upgrade via a script, diff them and manually apply changes to the live file. After all, you never really know what changes you actually want to apply.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.