How to work with multiple NodeJS versions using fnm?
Working with multiple NodeJS projects can be challenging at times with different NodeJS version requirements. There are multiple tools that can help with working with multiple versions like
- fnm (My go-to approach which is performance and version oriented, for non docker projects)
- Docker (Always suggest going for docker setup, read the article below for more)
After working with multiple node version managers, my personal favorite, recently has become,
fnmdue to its performance and simplicity.
mac users using homebrew
brew install fnm
fnm list- shows all the node versions installed in the system
fnm list-remote- Shows all the available node versions which can be installed.
fnm install <version>- Install the node version locally which we got from list command. eg-
fnm install v14.0.2would install
fnm use <version>- Activate the given version which is installed in the system. eg -
fnm use v16.13.2would activate
v16.13.2which is installed
fnm default <version>- Set the node version to default alias. eg
fnm default v16.13.2would make
v16.13.2as the default version for the system.
fnm current- Prints the current node version which is activated.
For more details on the available command, please check the below documentation