Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

node.js

People also ask

Should I use N or NVM?

If you're using Windows , there's no choice but to use n , or get a Mac . If you switch node versions frequently (e.g., to test the latest version of a feature locally, while keeping your code compatible in production), you should only use nvm for global module compatibility reasons.

Why is the NVM tool used to manage node js?

nvm stands for Node Version Manager. As the name suggests, it helps you manage and switch between different Node versions with ease. It provides a command-line interface where you can install different versions with a single command, set a default, switch between them and much more.

Is NVM the best way to install node?

Node Version Manager, more commonly called nvm, is the most popular way to install multiple versions of Node. js, but is only available for Mac/Linux and not supported on Windows. Instead, we recommend installing nvm-windows and then using it to install Node. js and Node Package Manager (npm).


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)