Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Unsolved
Collapse
Discussion Forum to share and further the development of home control and automation, independent of platforms.
  1. Home
  2. Software
  3. Multi-System Reactor
  4. Help updating node.js for bare metal install
How to upgrade from an old version of MSR?
cw-kidC
Hello I haven't updated my installation of MSR in a very long time. Its a bare metal Linux install currently on version 24366-3de60836 I see the latest version is now latest-26011-c621bbc7 I assume I cannot just jump from a very old version to the latest version? Or can I? Thanks
Multi-System Reactor
Access control - allowing anonymous user to dashboard
tunnusT
Using build 25328 and having the following users.yaml configuration: users: # This section defines your valid users. admin: ******* groups: # This section defines your user groups. Optionally, it defines application # and API access restrictions (ACLs) for the group. Users may belong to # more than one group. Again, no required or special groups here. admin_group: users: - admin applications: true # special form allows access to ALL applications guests: users: "*" applications: - dashboard api_acls: # This ACL allows users in the "admin" group to access the API - url: "/api" group: admin_group allow: true log: true # This ACL allows anyone/thing to access the /api/v1/alive API endpoint - url: "/api/v1/alive" allow: true session: timeout: 7200 # (seconds) rolling: true # activity extends timeout when true # If log_acls is true, the selected ACL for every API access is logged. log_acls: true # If debug_acls is true, even more information about ACL selection is logged. debug_acls: true My goal is to allow anonymous user to dashboard, but MSR is still asking for a password when trying to access that. Nothing in the logs related to dashboard access. Probably an error in the configuration, but help needed to find that. Tried to put url: "/dashboard" under api_acls, but that was a long shot and didn't work.
Multi-System Reactor
VEC Virtual Switch Auto Off
S
I use Virtual Entity Controller virtual switches which I turn on via webhooks from other applications. Once a switch triggers and turns on, I can then activate associated rules. I would like each virtual switch to automatically turn off after a configurable time (e.g., 5 seconds, 10 seconds). Is there a better way to achieve this auto-off behavior instead of creating a separate rule for each switch that uses the 'Condition must be sustained for' option to turn it off? With a large number of these switches (and the associated turn-off rules), I'm checking to see if there is a simpler approach.If not, could this be a feature request to add an auto-off timer directly to the virtual switches. Thanks Reactor (Multi-hub) latest-26011-c621bbc7 VirtualEntityController v25356 Synology Docker
Multi-System Reactor
Upcoming Storage Change -- Got Back-ups?
toggledbitsT
TL;DR: Format of data in storage directory will soon change. Make sure you are backing up the contents of that directory in its entirety, and you preserve your backups for an extended period, particularly the backup you take right before upgrading to the build containing this change (date of that is still to be determined, but soon). The old data format will remain readable (so you'll be able to read your pre-change backups) for the foreseeable future. In support of a number of other changes in the works, I have found it necessary to change the storage format for Reactor objects in storage at the physical level. Until now, plain, standard JSON has been used to store the data (everything under the storage directory). This has served well, but has a few limitations, including no real support for native JavaScript objects like Date, Map, Set, and others. It also is unable to store data that contains "loops" — objects that reference themselves in some way. I'm not sure exactly when, but in the not-too-distant future I will publish a build using the new data format. It will automatically convert existing JSON data to the new format. For the moment, it will save data in both the new format and the old JSON format, preferring the former when loading data from storage. I have been running my own home with this new format for several months, and have no issues with data loss or corruption. A few other things to know: If you are not already backing up your storage directory, you should be. At a minimum, back this directory up every time you make big changes to your Rules, Reactions, etc. Your existing JSON-format backups will continue to be readable for the long-term (years). The code that loads data from these files looks for the new file format first (which will have a .dval suffix), and if not found, will happily read (and convert) a same-basenamed .json file (i.e. it looks for ruleid.dval first, and if it doesn't find it, it tries to load ruleid.json). I'll publish detailed instructions for restoring from old backups when the build is posted (it's easy). The new .dval files are not directly human-readable or editable as easily as the old .json files. A new utility will be provided in the tools directory to convert .dval data to .json format, which you can then read or edit if you find that necessary. However, that may not work for all future data, as my intent is to make more native JavaScript objects directly storable, and many of those objects cannot be stored in JSON. You may need to modify your backup tools/scripts to pick up the new files: if you explicitly name .json files (rather than just specifying the entire storage directory) in your backup configuration, you will need to add .dval files to get a complete, accurate backup. I don't think this will be an issue for any of you; I imagine that you're all just backing up the entire contents of storage regardless of format/name, that is the safest (and IMO most correct) way to go (if that's not what you're doing, consider changing your approach). The current code stores the data in both the .dval form and the .json form to hedge against any real-world problems I don't encounter in my own use. Some future build will drop this redundancy (i.e. save only to .dval form). However, the read code for the .json form will remain in any case. This applies only to persistent storage that Reactor creates and controls under the storage tree. All other JSON data files (e.g. device data for Controllers) are unaffected by this change and will remain in that form. YAML files are also unaffected by this change. This thread is open for any questions or concerns.
Multi-System Reactor
Oddness in Copy/Move of Reactions
G
Topic thumbnail image
Multi-System Reactor
[Solved] function isRuleEnabled() issue
CrilleC
Topic thumbnail image
Multi-System Reactor
[Reactor] Problem with Global Reactions and groups
therealdbT
Topic thumbnail image
Multi-System Reactor
Possible feature request 2?
CatmanV2C
Just another thought. Adding devices from my Home Assistant / Zigbee2MQTT integration. Works perfectly but they always add as their IEEE address. Some of these devices have up to 10 entities associated, and the moment they are renamed to something sensible, each of those entities 'ceases to exist' in MSR. I like things tidy, and deleting each defunct entity needs 3 clicks. Any chance of a 'bulk delete' option? No biggy as I've pretty much finished my Z-wave migration and I don't expect to be adding more than 2 new Zigbee devices Cheers C
Multi-System Reactor
Reactor (Multi-System/Multi-Hub) Announcements
toggledbitsT
Build 21228 has been released. Docker images available from DockerHub as usual, and bare-metal packages here. Home Assistant up to version 2021.8.6 supported; the online version of the manual will now state the current supported versions; Fix an error in OWMWeatherController that could cause it to stop updating; Unify the approach to entity filtering on all hub interface classes (controllers); this works for device entities only; it may be extended to other entities later; Improve error detail in messages for EzloController during auth phase; Add isRuleSet() and isRuleEnabled() functions to expressions extensions; Implement set action for lock and passage capabilities (makes them more easily scriptable in some cases); Fix a place in the UI where 24-hour time was not being displayed.
Multi-System Reactor
Copying a global reaction
tunnusT
With build 25328, if you copy a global reaction, a new reaction does not appear in the UI unless you do a refresh. I recall this used to work without needing this page refresh? Anyway, only a minor nuisance.
Multi-System Reactor
[Reactor] Bug when sending MQTT boolean payloads
therealdbT
Topic thumbnail image
Multi-System Reactor
Difficulty defining repeating annual period
R
I have tried numerous ways to define a recurring annual period, for example from December 15 to January 15. No matter which method I try - after and before, between, after and/not after, Reactor reports "waiting for invalid date, invalid date. Some constructs also seem to cause Reactor to hang, timeout and restart. For example "before January 15 is evaluated as true, but reports "waiting for invalid date, invalid date". Does anyone have a tried and true method to define a recurring annual period? I think the "between" that I used successfully in the past may have broken with one of the updates.
Multi-System Reactor
Need help with sequence
T
Good evening all, For about the past week or so, I've been having problems with a specific rule in my home automation that controls when my home goes from an Away mode to Home mode. One of the conditions it checked for was my alarm panel, when it changed from Armed Away to Disarmed. There seems to have been a firmware update on the panel that added an intermittent step of "pending", and I can't say for certain it happens 100% of the time. Is there a way to write a condition that so it changes from one condition, to the next, and then another condition? As in, Home alarm changes from armed_away to pending to disarmed. Thanks.
Multi-System Reactor
Possible feature request?
CatmanV2C
No idea how easy this would be. During my migration away from Z-wave I've been replacing the Z-wave devices with Sonoff which has broken some of my automations. Any chance of a 'Test Reaction' function to call out which ones are broken because an entity no longer exists? Without actually running the reaction? Or does this exist already and I'm just not aware of how to do it? Obviously I can see entities that are no longer available, but not quite what I'm looking for. I guess it's something of an edge case so no huge issue. TIA! C
Multi-System Reactor
Logic Assistance: Exterior Lights on when Illuminance Below Threshold
PablaP
Topic thumbnail image
Multi-System Reactor
Time series documentation
tunnusT
Is the current manual (incl. examples) up to date with how retention value is handled in time series configuration? Referring to this post
Multi-System Reactor
MQTT templates for ZIgbee scene controller, or a better way?
CatmanV2C
Topic thumbnail image
Multi-System Reactor
Reset a delay
CatmanV2C
I'm sure this has been asked, and answered, but damned if I can figure it out Use case: I have a rear garden with lights. A door from the kitchen into the garden and a door from the garage. Currently if I open the kitchen door the lights come on (yay) and a 3 minute delay starts. After 3 minutes, no matter what else happens, the lights go off (Boo! But also yay!) What I would like is for the 3 minute delay until the lights go off to start from the latest door open event. That is, if I'm going from kitchen to garage, and back again, the lights stay on until there's three minutes of no activity. I've tried 'hacking' with a virtual switch, but can't seem to stop the delay. Any pointers? TIA C
Multi-System Reactor
Reactor Loading Screen Safari
S
Topic thumbnail image
Multi-System Reactor
Constraints states visually do not match actual
S
Topic thumbnail image
Multi-System Reactor

Help updating node.js for bare metal install

Scheduled Pinned Locked Moved Multi-System Reactor
14 Posts 6 Posters 7.5k Views 6 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • cw-kidC Offline
    cw-kidC Offline
    cw-kid
    wrote on last edited by
    #3

    This is the contents of that log file it mentioned:

    0 verbose cli /usr/bin/node /usr/bin/npm
    1 info using npm@8.19.4
    2 info using node@v16.20.2
    3 timing npm:load:whichnode Completed in 1ms
    4 timing config:load:defaults Completed in 7ms
    5 timing config:load:file:/usr/lib/node_modules/npm/npmrc Completed in 3ms
    6 timing config:load:builtin Completed in 3ms
    7 timing config:load:cli Completed in 10ms
    8 timing config:load:env Completed in 1ms
    9 timing config:load:project Completed in 26ms
    10 timing config:load:file:/root/.npmrc Completed in 10ms
    11 timing config:load:user Completed in 11ms
    12 timing config:load:file:/usr/etc/npmrc Completed in 1ms
    13 timing config:load:global Completed in 1ms
    14 timing config:load:validate Completed in 1ms
    15 timing config:load:credentials Completed in 6ms
    16 timing config:load:setEnvs Completed in 4ms
    17 timing config:load Completed in 73ms
    18 timing npm:load:configload Completed in 74ms
    19 timing npm:load:mkdirpcache Completed in 4ms
    20 timing npm:load:mkdirplogs Completed in 1ms
    21 verbose title npm install npm@10.2.5
    22 verbose argv "install" "--global" "npm@10.2.5"
    23 timing npm:load:setTitle Completed in 5ms
    24 timing config:load:flatten Completed in 14ms
    25 timing npm:load:display Completed in 24ms
    26 verbose logfile logs-max:10 dir:/root/.npm/_logs
    27 verbose logfile /root/.npm/_logs/2023-12-08T14_42_53_914Z-debug-0.log
    28 timing npm:load:logFile Completed in 25ms
    29 timing npm:load:timers Completed in 0ms
    30 timing npm:load:configScope Completed in 0ms
    31 timing npm:load Completed in 138ms
    32 silly logfile start cleaning logs, removing 1 files
    33 silly logfile done cleaning log files
    34 http fetch GET 200 https://registry.npmjs.org/npm 126ms (cache hit)
    35 timing command:install Completed in 275ms
    36 verbose stack Error: Unsupported engine
    36 verbose stack     at Object.checkEngine (/usr/lib/node_modules/npm/node_modules/npm-install-checks/lib/index.js:14:25)
    36 verbose stack     at Install.exec (/usr/lib/node_modules/npm/lib/commands/install.js:109:16)
    36 verbose stack     at async module.exports (/usr/lib/node_modules/npm/lib/cli.js:78:5)
    37 verbose pkgid npm@10.2.5
    38 verbose cwd /root
    39 verbose Linux 4.19.0-21-amd64
    40 verbose node v16.20.2
    41 verbose npm  v8.19.4
    42 error code EBADENGINE
    43 error engine Unsupported engine
    44 error engine Not compatible with your version of node/npm: npm@10.2.5
    45 error notsup Not compatible with your version of node/npm: npm@10.2.5
    45 error notsup Required: {"node":"^18.17.0 || >=20.5.0"}
    45 error notsup Actual:   {"npm":"8.19.4","node":"v16.20.2"}
    46 verbose exit 1
    47 timing npm Completed in 774ms
    48 verbose code 1
    49 error A complete log of this run can be found in:
    49 error     /root/.npm/_logs/2023-12-08T14_42_53_914Z-debug-0.log
    
    
    1 Reply Last reply
    0
    • PablaP Offline
      PablaP Offline
      Pabla
      wrote on last edited by Pabla
      #4

      So i ran into almost the exact same issue and this is how I managed to update NodeJS. Instead of running sudo apt update and sudo apt upgrade I followed the install instructions on NodeJS Github.

      To make Reactor happy I copied the path the old nodejs file was in and in my case it was /home/arman/.local/lib/nodejs I believe yours looks like it should be the same. Before doing anything copy and delete the NodeJS folder and put it somewhere where you can access it again if you run into any issues. Following the steps replace anywhere where it says /usr/local/lib/nodejs with /home/{user}/.local/lib/nodejs. This is where I have a band-aid repair to get Reactor back up and working. I renamed the new folder in the /home/{user}/.local/lib/nodejs directory from the new version of NodeJS to the previous version. In my case it I changed it from node-v20.10.0-linux-armv7l to node-v16.15.1-linux-armv7l. Then Reactor was happy and no error saying I need to update Node. This is a temporary fix however.

      I am no Linux expert so please take my advice with caution lol!

      1 Reply Last reply
      0
      • G Offline
        G Offline
        gwp1
        wrote on last edited by
        #5

        I had same issue and went back to the MSR manual where it noted if you didn't have a system install of nodejs MSR would do a local one for just it's user.

        I reran the opening steps from the manual and it updated to 18.x just fine.

        *Hubitat C-7 2.4.3.177
        *Proxmox VE v8, Beelink MiniPC 12GBs, SSD

        *HAOS
        Core 2026.1.1
        w/ HA Connect ZWA-2
        FW: v1.1
        SDK: v7.23.1

        *Prod MSR in docker/portainer
        MSR: latest-26011-c621bbc7
        MQTTController: 25139
        ZWave Controller: 25139

        1 Reply Last reply
        0
        • cw-kidC Offline
          cw-kidC Offline
          cw-kid
          wrote on last edited by cw-kid
          #6

          Thanks for the replies and tips.

          In the end after more Googling for my Debian Buster install this seems to have fixed it for me.

          I removed the new /usr/local/bin/node directory that got installed the other day.

          rm /usr/local/bin/node

          Then running the command "which node" the path was back to the old path of /usr/bin/node and "node -v" was showing the old version again of 16.20.2

          I then found these commands on Google and tried them:

          curl -fsSL https://deb.nodesource.com/setup_current.x | sudo -E bash -

          sudo apt-get install -y nodejs

          This seems to have upgraded the 16.20.2 version with a newer version, I saw this line in the terminal output

          Unpacking nodejs (20.5.1-deb-1nodesource1) over (16.20.2-deb-1nodesource1)

          Now when I do a node -v it says its version 20.5.1 and the alert message in MSR has now gone.

          "which node" still says the path is the original path of /usr/bin/node also.

          I have no idea if this was the correct way to do it but I think it has worked.

          1 Reply Last reply
          0
          • wmarcolinW Offline
            wmarcolinW Offline
            wmarcolin
            wrote on last edited by
            #7

            I think we all have a similar problem. My step-by-step was as follows.

            sudo apt remove nodejs
            sudo apt remove npm
            sudo apt autoremove
            
            sudo apt purge nodejs
            sudo apt purge npm
            sudo apt autoremove
            
            sudo apt-get update
            sudo apt-get install -y ca-certificates curl gnupg
            sudo mkdir -p /etc/apt/keyrings
            curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
            
            NODE_MAJOR=20
            echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
            
            sudo apt-get update
            sudo apt-get install nodejs -y
            

            Now comes the very rare story, if I'm not as toot I get this information.

            node -v
            v20.10.0
            
            npm -v
            10.2.3
            
            

            PERFECT!!

            But after the su --, I become root and the version that comes is 12? and then I really don't understand. I did the tasks like this, as root and without root, in the same way.

            If any expert can help me understand this madness.

            Thanks.

            1 Reply Last reply
            0
            • toggledbitsT Offline
              toggledbitsT Offline
              toggledbits
              wrote on last edited by
              #8

              The PATH environment variable for root is different from that of regular users. You can echo $PATH in each to see the differences. The path is processed in order, first come first served.

              Author of Multi-system Reactor and Reactor, DelayLight, Switchboard, and about a dozen other plugins that run on Vera and openLuup.

              1 Reply Last reply
              1
              • wmarcolinW Offline
                wmarcolinW Offline
                wmarcolin
                wrote on last edited by
                #9

                Well, I've just solved my problem, whether it's the right way or not I can't say, but it was brute force, I used the "which node" command, I located all the directories regardless of version and deleted them (rm node -r), this while being root. Then I did a fresh install 🙂 solved.

                toggledbitsT 1 Reply Last reply
                0
                • wmarcolinW wmarcolin

                  Well, I've just solved my problem, whether it's the right way or not I can't say, but it was brute force, I used the "which node" command, I located all the directories regardless of version and deleted them (rm node -r), this while being root. Then I did a fresh install 🙂 solved.

                  toggledbitsT Offline
                  toggledbitsT Offline
                  toggledbits
                  wrote on last edited by toggledbits
                  #10

                  @wmarcolin That may have worked, but it's not strictly right and may lead to complications down the road, like versions of node and npm being out of sync.

                  NOTE: Some of this can be used as instructions. Read all carefully and understand what you are doing before you actually do anything. If you don't understand, ask first, understand first, then proceed (always with caution and careful attention to detail).

                  Generally speaking, it's not a good idea to tamper with the system-installed version of any utility if there is one. If you use a command like apt-get install node or similar and it puts a version into /usr/bin, that's where you should leave it, and never change it (unless apt or yum does). That's because the system packages are versioned together as a group, so other system utilities may have dependencies on that system-blessed version of the package and its associated utilities and libraries.

                  When you want a newer version of node, the generally-recommended way is to do a custom install, which can be done either to a user-specific directory (so that one user can have a private version), or system-wide in a location under /usr/local (usually installed in /usr/local/lib with symbolic links from /usr/local/bin for the executables).

                  Either way, the version of node that runs is the first one encountered in the PATH environment then in effect.

                  Reactor has been tested with all three common install methods: the native system packages, when up to date; a /usr/local install; and a user-directory-specific install. All work fine.

                  Taking the structure of one of my RPis running Raspbian Buster (Debian 10), but should apply to almost any Linux-based platform...

                  The default system install puts a node and npm in /usr/bin:

                  pi@rpi4-2:~ $ ls -l /usr/bin/node
                  -rwxr-xr-x 1 root root 5536 Feb 24  2023 /usr/bin/node
                  pi@rpi4-2:~ $ /usr/bin/node -v
                  v10.24.0
                  pi@rpi4-2:~ $
                  

                  Notice that when I ran the node command, I ran it with a full path (i.e. as /usr/bin/node and not just typing node). That's because I have a newer version of node installed in /usr/local that is configured to take precedence. And also notice how old that system-installed package is!

                  My later-version installation in /usr/local/lib (specifically) looks like this:

                  pi@rpi4-2:~ $ ls -l /usr/local/lib/
                  total 12
                  drwxr-xr-x 3 root root  4096 Nov 26 08:59 nodejs
                  drwxrwsr-x 4 root staff 4096 Nov 26 09:13 python2.7
                  drwxrwsr-x 3 root staff 4096 May  7  2021 python3.7
                  pi@rpi4-2:~ $ ls -l /usr/local/lib/nodejs
                  total 42112
                  drwxr-xr-x 6 1001 1001     4096 Oct 13 10:03 node-v18.18.2-linux-armv7l
                  -rw-r--r-- 1 root root 20932900 Oct 13 10:05 node-v18.18.2-linux-armv7l.tar.xz
                  -rw-r--r-- 1 root root 22182716 Nov 22 07:30 node-v20.10.0-linux-armv7l.tar.xz
                  pi@rpi4-2:~ $
                  

                  You can see here, I have a nodejs subdirectory in /usr/local/lib. In here, I've got the downloaded archives for two versions (an 18 and a 20), of which the 18 is currently unpacked in the directory node-v18.18.2-linux-armv7l. That's a completely self-contained package for nodejs, ready to run. All that was needed was to configure it to run.

                  Configuring this version of node to run took two additional steps. First, I went to /usr/local/bin, and symbolically linked the executables from the v18 package, like this (notice I'm doing this step as root) :

                  root@rpi4-2:~# cd /usr/local/bin
                  root@rpi4-2:/usr/local/bin# ln -sf /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/* .
                  root@rpi4-2:/usr/local/bin# ls -l
                  total 4
                  lrwxrwxrwx 1 root root 61 Dec 11 12:30 corepack -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/corepack
                  lrwxrwxrwx 1 root root 57 Dec 11 12:30 node -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/node
                  lrwxrwxrwx 1 root root 56 Dec 11 12:30 npm -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/npm
                  lrwxrwxrwx 1 root root 56 Dec 11 12:30 npx -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/npx
                  root@rpi4-2:/usr/local/bin#
                  

                  The first command changes directory to /usr/local/bin, and the second symbolically links all files in the package's bin subdirectory to the current directory (which is our /usr/local/bin). The ls command shows the result of that operation. So you can see, the executable in /usr/local/bin/node isn't an executable at all, it's a symbolic link to the executable in the package directory. Same with the other nodejs commands in the package.

                  The last step is to get that executable in /usr/local/bin/node to take precedence over the older version in the system install (i.e. the one in /usr/bin/node). All that is required to do this is that /usr/local/bin/node be seen by the shell before /usr/bin/node. This is done by making sure /usr/local/bin comes before /usr/bin in the PATH environment variable. On most systems, this is already the default case -- it's set up that way and you don't need to do anything. On some systems, you may need to add it. This can be done by adding a snippet like the following to the end of /etc/profile (to make it a system-wide change):

                  PATH=/usr/local/bin:$PATH
                  export PATH
                  

                  This puts /usr/local/bin at the head of the PATH. Again, this usually isn't necessary, because /usr/local/bin is already early in the path on most systems by default. You can check your path by doing echo $PATH as I said before. If you do end up having to make this change, you'll need to log out and log back in to make it take effect. And, any time you edit anything in /etc, it's a good idea to make a backup copy of the unmodified file first, in case you goof something up and need to revert (cp /etc/profile /etc/profile.old is sufficient).

                  If you're installing a per-user version of nodejs, the structure is fairly similar, but rather than unpacking the nodejs archive into /usr/local/lib/nodejs, you unpack it into ~/.local/lib/nodejs/ (remember ~ is a synonym for $HOME and means the current user's home directory path) with the same structure that I showed above for /usr/local/.... Notice we are not root here!

                  # For user-local install, all work is done NOT as root. Here, I'm just "pi"
                  pi@rpi4-2:~ $ mkdir -p ~/.local/lib
                  pi@rpi4-2:~ $ mkdir -p ~/.local/bin
                  pi@rpi4-2:~ $ cd ~/.local/lib/
                  pi@rpi4-2:~/.local/lib $ mkdir -p nodejs
                  pi@rpi4-2:~/.local/lib $ cd nodejs
                  pi@rpi4-2:~/.local/lib/nodejs $ wget 'https://nodejs.org/dist/latest-v20.x/node-v20.10.0-linux-armv7l.tar.xz'
                  --2023-12-11 12:46:55--  https://nodejs.org/dist/latest-v20.x/node-v20.10.0-linux-armv7l.tar.xz
                  Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:162e, ...
                  Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
                  HTTP request sent, awaiting response... 200 OK
                  Length: 22182716 (21M) [application/x-xz]
                  Saving to: ânode-v20.10.0-linux-armv7l.tar.xz.1â
                  
                  node-v20.10.0-linux-armv7l.tar.x 100%[==========================================================>]  21.15M  18.5MB/s    in 1.1s
                  
                  2023-12-11 12:46:57 (18.5 MB/s) - ânode-v20.10.0-linux-armv7l.tar.xz.1â saved [22182716/22182716]
                  
                  pi@rpi4-2:~/.local/lib/nodejs $ ls
                  node-v20.10.0-linux-armv7l.tar.xz
                  pi@rpi4-2:~/.local/lib/nodejs $ tar xJf node-v20.10.0-linux-armv7l.tar.xz    # J is for .xz, z is for .gz
                  pi@rpi4-2:~/.local/lib/nodejs $ cd ~/.local/bin
                  pi@rpi4-2:~/.local/bin $ ln -sf ~/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/* .
                  pi@rpi4-2:~/.local/bin $ ls -l
                  total 16
                  lrwxrwxrwx 1 pi pi 66 Dec 11 12:48 corepack -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/corepack
                  lrwxrwxrwx 1 pi pi 62 Dec 11 12:48 node -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/node
                  lrwxrwxrwx 1 pi pi 61 Dec 11 12:48 npm -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/npm
                  lrwxrwxrwx 1 pi pi 61 Dec 11 12:48 npx -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/npx
                  pi@rpi4-2:~/.local/bin $
                  

                  Reading these steps, the first five commands create the structure of the .local subdirectory needed, with subdirectories bin, lib and lib/nodejs within just like we would have in /usr/local. At this point, the current directory is ~/.local/lib/nodejs, and the wget command is used to download the nodejs package we want (change version and architecture to what you need if you are actually doing this). Then we un-tar it right where we are. After un-taring it, we change directory to our own ~/.local/bin and make the symbolic links for the nodejs commands in the package directory, just like we did for /usr/local.

                  The last step is again, and this may be default, is making sure this user's PATH environment variable includes our new local ~/.local/bin directory. Check it with echo $PATH to see if you need to make the addition. If so, the easiest way to do that is to add the following snipped to ~/.profile, which is the per-user equivalent to /etc/profile (the per-user script runs after the /etc script at login) to set up the shell environment. My Raspbian Buster (Debian 10) systems seem to have this done already as a default, so before making any changes, check your PATH and/or ~/.profile.

                  PATH=$HOME/.local/bin:$PATH
                  export PATH
                  

                  Log out and back in, and then a which node should give you ~/.local/bin/node (or /home/username/.local/bin/node). You then have a per-user custom version of nodejs that doesn't interfere with any system versions.

                  Now, for running Reactor as a service, you need to be aware of where you are running it, and as who. It's generally not recommended to run Reactor as root on any bare-metal system (it runs as root on docker containers, but that's OK because the container is a constrained virtual environment). So when setting up, for example, your systemd profile for Reactor, you would want to make sure the profile contains both a User directory to set the correct (non-root) user for the running process, and a full path to the correct node executable in ExecStart (e.g. ExecStart=/home/pi/.local/bin/node app -p).

                  One last point: nodejs is so well-written that its entire dependencies exist entirely within its package structure, so whatever node command runs knows automatically where to find everything else it needs — you don't need to set a bunch of other environment variables to make each version work properly. That means you could, for example, run /usr/bin/node and see a perfectly working v10.24.0 as I showed above, or /usr/local/bin/node and get a perfectly-working v18.18.2 if that's what is installed there, and ~/.local/bin/node to get a fine v20.9.0 environment if that's what's installed there. Not all packages are this tight, and we can be grateful for it.

                  Tip: don't stop at which node when you are trying to figure out what is running. nodejs itself makes extensive use of symbolic links, so doing which node is only the tip of the iceberg. You need to then do ls -l /that-path and see if it's a symbolic link to somewhere else, as I showed in the output above. Keep following those links until you find the "real deal" and you'll find which version is actually running and where it actually lives.

                  I hope some of this clarifies how nodejs is installed, and highlights how you can actually have multiple versions of it installed on the system and they co-exist quite well, you just have to be careful.

                  Author of Multi-system Reactor and Reactor, DelayLight, Switchboard, and about a dozen other plugins that run on Vera and openLuup.

                  wmarcolinW 1 Reply Last reply
                  3
                  • CatmanV2C Offline
                    CatmanV2C Offline
                    CatmanV2
                    wrote on last edited by
                    #11

                    @toggledbits fabulous post, there. Thanks. 18.19.0 in /usr/local/bin for Reactor and, apparently working fine 🙂

                    Any particular reason not to go to 21?

                    Cheers

                    C

                    The Ex-Vera abuser know as CatmanV2.....

                    toggledbitsT 1 Reply Last reply
                    0
                    • CatmanV2C CatmanV2

                      @toggledbits fabulous post, there. Thanks. 18.19.0 in /usr/local/bin for Reactor and, apparently working fine 🙂

                      Any particular reason not to go to 21?

                      Cheers

                      C

                      toggledbitsT Offline
                      toggledbitsT Offline
                      toggledbits
                      wrote on last edited by toggledbits
                      #12

                      @CatmanV2 said in Help updating node.js for bare metal install:

                      Any particular reason not to go to 21?

                      Yes! Only even-numbered versions of nodejs are LTS (long-term support). For the longest life of the system between upgrades like this, use the LTS versions only. That's why I recommend 18 and 20.

                      Here's their release and support calendar: https://nodejs.github.io/nodejs.dev/en/about/releases/

                      Notice that 21 will be EOL far sooner than either 18 or 20.

                      Author of Multi-system Reactor and Reactor, DelayLight, Switchboard, and about a dozen other plugins that run on Vera and openLuup.

                      1 Reply Last reply
                      1
                      • CatmanV2C Offline
                        CatmanV2C Offline
                        CatmanV2
                        wrote on last edited by
                        #13

                        Doh! Thanks for that!

                        C

                        The Ex-Vera abuser know as CatmanV2.....

                        1 Reply Last reply
                        0
                        • toggledbitsT toggledbits

                          @wmarcolin That may have worked, but it's not strictly right and may lead to complications down the road, like versions of node and npm being out of sync.

                          NOTE: Some of this can be used as instructions. Read all carefully and understand what you are doing before you actually do anything. If you don't understand, ask first, understand first, then proceed (always with caution and careful attention to detail).

                          Generally speaking, it's not a good idea to tamper with the system-installed version of any utility if there is one. If you use a command like apt-get install node or similar and it puts a version into /usr/bin, that's where you should leave it, and never change it (unless apt or yum does). That's because the system packages are versioned together as a group, so other system utilities may have dependencies on that system-blessed version of the package and its associated utilities and libraries.

                          When you want a newer version of node, the generally-recommended way is to do a custom install, which can be done either to a user-specific directory (so that one user can have a private version), or system-wide in a location under /usr/local (usually installed in /usr/local/lib with symbolic links from /usr/local/bin for the executables).

                          Either way, the version of node that runs is the first one encountered in the PATH environment then in effect.

                          Reactor has been tested with all three common install methods: the native system packages, when up to date; a /usr/local install; and a user-directory-specific install. All work fine.

                          Taking the structure of one of my RPis running Raspbian Buster (Debian 10), but should apply to almost any Linux-based platform...

                          The default system install puts a node and npm in /usr/bin:

                          pi@rpi4-2:~ $ ls -l /usr/bin/node
                          -rwxr-xr-x 1 root root 5536 Feb 24  2023 /usr/bin/node
                          pi@rpi4-2:~ $ /usr/bin/node -v
                          v10.24.0
                          pi@rpi4-2:~ $
                          

                          Notice that when I ran the node command, I ran it with a full path (i.e. as /usr/bin/node and not just typing node). That's because I have a newer version of node installed in /usr/local that is configured to take precedence. And also notice how old that system-installed package is!

                          My later-version installation in /usr/local/lib (specifically) looks like this:

                          pi@rpi4-2:~ $ ls -l /usr/local/lib/
                          total 12
                          drwxr-xr-x 3 root root  4096 Nov 26 08:59 nodejs
                          drwxrwsr-x 4 root staff 4096 Nov 26 09:13 python2.7
                          drwxrwsr-x 3 root staff 4096 May  7  2021 python3.7
                          pi@rpi4-2:~ $ ls -l /usr/local/lib/nodejs
                          total 42112
                          drwxr-xr-x 6 1001 1001     4096 Oct 13 10:03 node-v18.18.2-linux-armv7l
                          -rw-r--r-- 1 root root 20932900 Oct 13 10:05 node-v18.18.2-linux-armv7l.tar.xz
                          -rw-r--r-- 1 root root 22182716 Nov 22 07:30 node-v20.10.0-linux-armv7l.tar.xz
                          pi@rpi4-2:~ $
                          

                          You can see here, I have a nodejs subdirectory in /usr/local/lib. In here, I've got the downloaded archives for two versions (an 18 and a 20), of which the 18 is currently unpacked in the directory node-v18.18.2-linux-armv7l. That's a completely self-contained package for nodejs, ready to run. All that was needed was to configure it to run.

                          Configuring this version of node to run took two additional steps. First, I went to /usr/local/bin, and symbolically linked the executables from the v18 package, like this (notice I'm doing this step as root) :

                          root@rpi4-2:~# cd /usr/local/bin
                          root@rpi4-2:/usr/local/bin# ln -sf /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/* .
                          root@rpi4-2:/usr/local/bin# ls -l
                          total 4
                          lrwxrwxrwx 1 root root 61 Dec 11 12:30 corepack -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/corepack
                          lrwxrwxrwx 1 root root 57 Dec 11 12:30 node -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/node
                          lrwxrwxrwx 1 root root 56 Dec 11 12:30 npm -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/npm
                          lrwxrwxrwx 1 root root 56 Dec 11 12:30 npx -> /usr/local/lib/nodejs/node-v18.18.2-linux-armv7l/bin/npx
                          root@rpi4-2:/usr/local/bin#
                          

                          The first command changes directory to /usr/local/bin, and the second symbolically links all files in the package's bin subdirectory to the current directory (which is our /usr/local/bin). The ls command shows the result of that operation. So you can see, the executable in /usr/local/bin/node isn't an executable at all, it's a symbolic link to the executable in the package directory. Same with the other nodejs commands in the package.

                          The last step is to get that executable in /usr/local/bin/node to take precedence over the older version in the system install (i.e. the one in /usr/bin/node). All that is required to do this is that /usr/local/bin/node be seen by the shell before /usr/bin/node. This is done by making sure /usr/local/bin comes before /usr/bin in the PATH environment variable. On most systems, this is already the default case -- it's set up that way and you don't need to do anything. On some systems, you may need to add it. This can be done by adding a snippet like the following to the end of /etc/profile (to make it a system-wide change):

                          PATH=/usr/local/bin:$PATH
                          export PATH
                          

                          This puts /usr/local/bin at the head of the PATH. Again, this usually isn't necessary, because /usr/local/bin is already early in the path on most systems by default. You can check your path by doing echo $PATH as I said before. If you do end up having to make this change, you'll need to log out and log back in to make it take effect. And, any time you edit anything in /etc, it's a good idea to make a backup copy of the unmodified file first, in case you goof something up and need to revert (cp /etc/profile /etc/profile.old is sufficient).

                          If you're installing a per-user version of nodejs, the structure is fairly similar, but rather than unpacking the nodejs archive into /usr/local/lib/nodejs, you unpack it into ~/.local/lib/nodejs/ (remember ~ is a synonym for $HOME and means the current user's home directory path) with the same structure that I showed above for /usr/local/.... Notice we are not root here!

                          # For user-local install, all work is done NOT as root. Here, I'm just "pi"
                          pi@rpi4-2:~ $ mkdir -p ~/.local/lib
                          pi@rpi4-2:~ $ mkdir -p ~/.local/bin
                          pi@rpi4-2:~ $ cd ~/.local/lib/
                          pi@rpi4-2:~/.local/lib $ mkdir -p nodejs
                          pi@rpi4-2:~/.local/lib $ cd nodejs
                          pi@rpi4-2:~/.local/lib/nodejs $ wget 'https://nodejs.org/dist/latest-v20.x/node-v20.10.0-linux-armv7l.tar.xz'
                          --2023-12-11 12:46:55--  https://nodejs.org/dist/latest-v20.x/node-v20.10.0-linux-armv7l.tar.xz
                          Resolving nodejs.org (nodejs.org)... 104.20.23.46, 104.20.22.46, 2606:4700:10::6814:162e, ...
                          Connecting to nodejs.org (nodejs.org)|104.20.23.46|:443... connected.
                          HTTP request sent, awaiting response... 200 OK
                          Length: 22182716 (21M) [application/x-xz]
                          Saving to: ânode-v20.10.0-linux-armv7l.tar.xz.1â
                          
                          node-v20.10.0-linux-armv7l.tar.x 100%[==========================================================>]  21.15M  18.5MB/s    in 1.1s
                          
                          2023-12-11 12:46:57 (18.5 MB/s) - ânode-v20.10.0-linux-armv7l.tar.xz.1â saved [22182716/22182716]
                          
                          pi@rpi4-2:~/.local/lib/nodejs $ ls
                          node-v20.10.0-linux-armv7l.tar.xz
                          pi@rpi4-2:~/.local/lib/nodejs $ tar xJf node-v20.10.0-linux-armv7l.tar.xz    # J is for .xz, z is for .gz
                          pi@rpi4-2:~/.local/lib/nodejs $ cd ~/.local/bin
                          pi@rpi4-2:~/.local/bin $ ln -sf ~/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/* .
                          pi@rpi4-2:~/.local/bin $ ls -l
                          total 16
                          lrwxrwxrwx 1 pi pi 66 Dec 11 12:48 corepack -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/corepack
                          lrwxrwxrwx 1 pi pi 62 Dec 11 12:48 node -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/node
                          lrwxrwxrwx 1 pi pi 61 Dec 11 12:48 npm -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/npm
                          lrwxrwxrwx 1 pi pi 61 Dec 11 12:48 npx -> /home/pi/.local/lib/nodejs/node-v20.10.0-linux-armv7l/bin/npx
                          pi@rpi4-2:~/.local/bin $
                          

                          Reading these steps, the first five commands create the structure of the .local subdirectory needed, with subdirectories bin, lib and lib/nodejs within just like we would have in /usr/local. At this point, the current directory is ~/.local/lib/nodejs, and the wget command is used to download the nodejs package we want (change version and architecture to what you need if you are actually doing this). Then we un-tar it right where we are. After un-taring it, we change directory to our own ~/.local/bin and make the symbolic links for the nodejs commands in the package directory, just like we did for /usr/local.

                          The last step is again, and this may be default, is making sure this user's PATH environment variable includes our new local ~/.local/bin directory. Check it with echo $PATH to see if you need to make the addition. If so, the easiest way to do that is to add the following snipped to ~/.profile, which is the per-user equivalent to /etc/profile (the per-user script runs after the /etc script at login) to set up the shell environment. My Raspbian Buster (Debian 10) systems seem to have this done already as a default, so before making any changes, check your PATH and/or ~/.profile.

                          PATH=$HOME/.local/bin:$PATH
                          export PATH
                          

                          Log out and back in, and then a which node should give you ~/.local/bin/node (or /home/username/.local/bin/node). You then have a per-user custom version of nodejs that doesn't interfere with any system versions.

                          Now, for running Reactor as a service, you need to be aware of where you are running it, and as who. It's generally not recommended to run Reactor as root on any bare-metal system (it runs as root on docker containers, but that's OK because the container is a constrained virtual environment). So when setting up, for example, your systemd profile for Reactor, you would want to make sure the profile contains both a User directory to set the correct (non-root) user for the running process, and a full path to the correct node executable in ExecStart (e.g. ExecStart=/home/pi/.local/bin/node app -p).

                          One last point: nodejs is so well-written that its entire dependencies exist entirely within its package structure, so whatever node command runs knows automatically where to find everything else it needs — you don't need to set a bunch of other environment variables to make each version work properly. That means you could, for example, run /usr/bin/node and see a perfectly working v10.24.0 as I showed above, or /usr/local/bin/node and get a perfectly-working v18.18.2 if that's what is installed there, and ~/.local/bin/node to get a fine v20.9.0 environment if that's what's installed there. Not all packages are this tight, and we can be grateful for it.

                          Tip: don't stop at which node when you are trying to figure out what is running. nodejs itself makes extensive use of symbolic links, so doing which node is only the tip of the iceberg. You need to then do ls -l /that-path and see if it's a symbolic link to somewhere else, as I showed in the output above. Keep following those links until you find the "real deal" and you'll find which version is actually running and where it actually lives.

                          I hope some of this clarifies how nodejs is installed, and highlights how you can actually have multiple versions of it installed on the system and they co-exist quite well, you just have to be careful.

                          wmarcolinW Offline
                          wmarcolinW Offline
                          wmarcolin
                          wrote on last edited by
                          #14

                          @toggledbits

                          Super thanks for the master class!!!!

                          1 Reply Last reply
                          1
                          • toggledbitsT toggledbits locked this topic on
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          Recent Topics

                          • HA and AI
                            CatmanV2C
                            CatmanV2
                            0
                            1
                            15

                          • How to upgrade from an old version of MSR?
                            CatmanV2C
                            CatmanV2
                            0
                            6
                            75

                          • Access control - allowing anonymous user to dashboard
                            toggledbitsT
                            toggledbits
                            0
                            2
                            79

                          • VEC Virtual Switch Auto Off
                            S
                            SweetGenius
                            1
                            1
                            54

                          • Upcoming Storage Change -- Got Back-ups?
                            toggledbitsT
                            toggledbits
                            3
                            1
                            49

                          • Oddness in Copy/Move of Reactions
                            G
                            gwp1
                            0
                            1
                            71

                          • [Solved] function isRuleEnabled() issue
                            CrilleC
                            Crille
                            0
                            4
                            129

                          • [Reactor] Problem with Global Reactions and groups
                            therealdbT
                            therealdb
                            0
                            3
                            131

                          • Possible feature request 2?
                            CatmanV2C
                            CatmanV2
                            0
                            3
                            107

                          • Reactor (Multi-System/Multi-Hub) Announcements
                            toggledbitsT
                            toggledbits
                            5
                            133
                            80.3k

                          • Genuinely impressed with Zigbee and HA / Reactor
                            CatmanV2C
                            CatmanV2
                            1
                            9
                            406

                          • Copying a global reaction
                            toggledbitsT
                            toggledbits
                            0
                            3
                            135
                          Powered by NodeBB | Contributors
                          Hosted freely by 10RUPTiV - Solutions Technologiques | Contact us
                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Unsolved