n or nvm for managing node versions - is keeping global modules for each version a good idea?

n is a Node module, which can be installed by npm, and nvm is a Bash script.

n and nvm are both still active projects, because it's still more of a bother than updating on Windows. They are still actively maintained, and both have been modified less than 10 days ago.

I find n to be of easier use because it can be installed by npm, but both scripts serve their purpose ;)


I will say if you don't need to work on different node versions and switch back and forth, n is far easier. For example when you use nvm to switch to a different node version all the global packages with the old version were "gone", you will have to install them again for the new version, for a production env it is a good thing but for the dev env it is quite annoying.

I have a project that started with node 6 (mac & Ubuntu) and in the past 2 years all I did was to first upgrade to node 8 (mainly to use async/await to avoid callback hell) then to node 10 (mainly to get a better performance with latest V8 Engine). I tried nvm and n and n is definitely easier.

---- update 2020.11.16 ----

After gaining more experience with n I do find n has an annoying problem: when n install failed (maybe due to network problem), it will also corrupt my existing node, following is an example. I have to reinstall node then.

AES-demo ➤ sudo n lts                                                                                                                               
curl: (35) LibreSSL SSL_connect: SSL_ERROR_SYSCALL in connection to nodejs.org:443

  Error: failed to download version index (https://nodejs.org/dist/index.tab)

// I guess it was due to the network failure because it then succeeded
AES-demo ➤ sudo n lts                                                                                                                                 

  installing : node-v14.15.1
....

//But then I hit the error, which means node was broken
/usr/local/bin/n: line 636: /usr/local/bin/node: No such file or directory
AES-demo ➤ node -v                                                                                                                                    
zsh: command not found: node 

I opened an issue against n https://github.com/tj/n/issues/634.

The problem is fixed in "Improvement released in v6.7.1." So be sure to install this latest version (as in 2020.11.23)

Tags:

Node.Js