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
- nvm
- n
- 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)
fnm
After working with multiple node version managers, my personal favorite, recently has become, fnm
due to its performance and simplicity.
Installing fnm
mac users using homebrew
brew install fnm
Using fnm
fnm list
- shows all the node versions installed in the systemfnm 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.2
would installv14.0.2
locally.fnm use <version>
- Activate the given version which is installed in the system. eg -fnm use v16.13.2
would activatev16.13.2
which is installedfnm default <version>
- Set the node version to default alias. egfnm default v16.13.2
would makev16.13.2
as 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