Change node version

Have some feedback, questions, suggestions, or just fancy a chat? Pop it in here.
Post Reply
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Change node version

Post by baz123 »

I've added a request for the ability to select the 'node' version to be installed. In the meantime, I need node v8.

I note in dietpi-software that in some cases this version is installed for specific packages - as an aside, this might be worth warning the user as they may wonder why node has gone to v8!

To downgrade node, 'n' is used. So I installed 'n' using that same command

Code: Select all

npm i -g --unsafe-perm n
. However, as the current install of node was not done by n, it doesn't know about it (feels like an infinite loop, need node for npm for n...).

I have node-red running some other stuff so I am rather concerned I may break something :(

What actually happens if I downgrade using `n 8`?
Does node-red then use V8?
Can I get back to the latest build? Should I simply use n to install v11?
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change node version

Post by MichaIng »

Jep, some software titles (still) require node 8, so within dietpi-software we manually downgrade via npm i -g --unsafe-perm n && n 8.
Not sure if users will even recognize if their node version changes, but jep a warning would be an idea, at least if Node was already installed before.

However, AFAIK when installing Node relying software, Node + modules are installed locally within the software install dir? But not sure and I think depends on the exact install method :?.

However it should not matter, since all software should as well run with Node 8. Would be a shot in the knee to drop LTS version support ;). Also AFAIK the old (respectively new v10) should be still available. The n versioning AFAIK places different versions beside each other. But not sure if this means that e.g. node-red will remain using v10 or always uses the one that was linked to the $PATH dirs (so v8), or even a locally within software install dir placed one. Should be also different depending on how the software and it's dependency node modules were actually installed.

Simply do a dietpi-backup and try it out. If anything fails, revert.

Hmm npm i -g --unsafe-perm n fails in your case?? This is strange, since it works well during our installs. Also we do not install npm/Node itself via n at first. Assure that you run it as root or with sudo.
Or is in your case Node not yet installed? Of course npm is only available if Node is installed first ;). In case you can install it via dietpi-software > Additional software (I believe) and then you can use n 8 to downgrade. Or let me check how to directly install Node v8, which should be cleaner of course.
meeki007
Posts: 2
Joined: Mon Nov 05, 2018 5:21 am

Re: Change node version

Post by meeki007 »

I've been stuck with the node-red version issue too.

the node-red install script points to:
INSTALL_URL_ADDRESS='http://raw.githubusercontent.com/taaem/ ... install.sh'

Well it would be nice to have an option to pick my version as i found

nightmare package requires a version of electron than runs on arm.
so Im stuck running electron 1.7.9 on a Node.js LTS 8
also some of my flows don't work because of non updated contrib-packages that dont have the new compiled depends.
I cant ever flash a new img of dietpi I keep upgrading my old image and then making a backup of it for later use.
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change node version

Post by MichaIng »

Indeed it is kinda mess. One can install node modules locally, but by default the version managers (nvm and n) do not support to install/use a specific node version per project/directory.
When using e.g. n 8, node 8 is installed besides node 10, but node 8 is then used for all projects, as well since the $PATH binaries all link to node 8 then.

I did some research and found another module: https://github.com/wbyoung/avn
This seems to allow automatically switching of the node version per directory/projekt.

When using n, do:

Code: Select all

npm install -g avn avn-n
avn setup
cd /path/to/node/project # that requires specific version, e.g. node 8
echo '8.12.0' > .node-version # most current version 8: https://nodejs.org/en/download/releases/
Not sure how this is done exactly, but worth trying. If this allows then to run/start different node projects in parallel and all of them automatically run with the specified version, then this is something we could indeed install by default with dietpi-software, when manually downgrading node.

Btw. Node 10 is new LTS, node 11 now available.
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Change node version

Post by baz123 »

Thanks all.

I installed node (by dietpi-software) followed by n using the method used by DietPi. n only recognises node versions installed by itself so I installed 8, LTS and Latest just for the hell of it.

Node-red then picks up what ever is in use. Not tried to switch as v8 works for the 2 NR modules I am using so I'm in a 'ain't broke don't fix' position :D .

Perhaps an option to install different versions via the menu would be useful plus a note for the 'standard' install that it installs the latest and not LTS.

Cheers all.
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change node version

Post by MichaIng »

The problem with leaving choose to user is that we would need to assure that all available choices actually work with the current software being installed.
But indeed the current solution implies the same issue, as a downgrade could break it for other software titles.

Is it an issue that n does not know about the pre-installed version? You only install it, when you want to install a certain different version and for this the pre-installed version should not be relevant? It will be then not used anyway.

But yeah looks like a general issue that it is not intended to run different node version on the same system concurrently. One can manually switch around versions via nvm/n, but only one version is globally used. Also I am not sure if there could appear issues, if e.g. a project + local modules is installed via Node 10, then n downgrades to Node 8 and then the other project might not work any more? Not sure about downwards compatibility.

So to assure flexibility and concurrently running node projects with different version requirements, the only viable solution seems to be avn. I will play with this and see if it works as expected, easy and automated.
If so, we can use this by default in our node software installs, to freeze each installed software Node version to guarantee function. Then inform user about this and link a simple howto for manually adding another Node project.

I opened a GitHub issue for investigation: https://github.com/Fourdee/DietPi/issues/2226
baz123
Posts: 166
Joined: Thu Jan 12, 2017 9:23 pm

Re: Change node version

Post by baz123 »

@MichaIng Just one other point of note, Node-Red currently recommends V8 of nodejs https://nodered.org/docs/getting-started/installation. I *think* a vanilla build of DietPi and install of Node-Red will end up with nodejs at *latest* (V11). Not 100% sure of that though....
User avatar
MichaIng
Site Admin
Posts: 2293
Joined: Sat Nov 18, 2017 6:21 pm

Re: Change node version

Post by MichaIng »

@baz123
Jep, currently Node 11 will be installed. However it works fine with Node-Red as far as I tested, so no need to change here.
Although I am not sure if certain modules might have different/own Node dependencies, which might be the reason why officially V8 is recommended to be most compatible.

Btw, I added the multiple Node versions request to our new FeatHub page: https://feathub.com/Fourdee/DietPi/+26

We simply have too much requests to handle them in reasonable time, so I just set up DietPi on FeatHub to have a better overview and priorities.
Post Reply