What I tested was to install Node-RED via dietpi-software on a fresh system.
Then, Node-Red 4.0.2 was installed.
In the internet I did not find any hints of upgrading which worked for me.
I tested these options, all without success. The system stayed at version 3.1.11:
An upgrade with sudo npm install -g --unsafe-perm node-red@next
A reinstall via dietpi-software reinstall 122
An uninstall/install via dietpi-software uninstall 122 && dietpi-software install 122 led to a fresh 4.0.2 installation without the old flows from the 3.1.11 version.
So the next try could be to export the whole flows in the Node-RED UI , then do an uninstall/install via dietpi-software uninstall 122 && dietpi-software install 122 and afterwards import the flows again.
This will not be the best solution, because - depending on the nodes you use - some node’s credentials will not be valid any more and need to be entered again.