It automatically changes node versions as you move between projects

NVM, the Node Version Manager, has been around almost as long as node itself (the first version was published about a year after Node was first released). It solved a really frustrating problem: different projects required different versions of node. Instead of downloading and installing a new binary from the internet every time you switched projects, nvm let you just nvm use 12.
-
It’s slow. If you have nvm automatically run on your shell startup, I would wager that it’s accounting for the majority of your shell startup lag. You won’t realize how long it’s taking until you remove it.
-
It still requires you to know that you need to switch node versions
- nvm supports an .nvmrc file but that still requires you to run an
nvmcommand (the rc file just specifies the correct version in that command for you).
- nvm supports an .nvmrc file but that still requires you to run an
- Shell startup for fnm is upwards of 50x faster than nvm. It is a difference you will notice immediately upon switching
- It automatically changes node versions to match any project that you
cdinto!
- It looks for a node version declared in
.node-versionor.nvmrcfiles, or theengines.nodefield of apackage.jsonfile.
- It looks for a node version declared in
fnm is another tool in your tool belt for shortening the list of things you have to think about to successfully run a web project:
- easy-install lets you not worry about which package manager is in use
- corepack lets you not worry about which version of that package manager is in use
- A package manager lets you not worry about which versions of all the dependencies are in use
lets you not worry about which node version is in usefnm
-
First delete nvm:
rm -rf ~/.nvm- Remove all references to it from your
~/.zshrcfile
-
Run the fnm auto install script:
Terminal window curl -fsSL https://fnm.vercel.app/install | bash -
Configure fnm to run on shell startup:
Terminal window eval "$(fnm completions --shell zsh)"eval "$(fnm env --use-on-cd --shell zsh --version-file-strategy=recursive --resolve-engines --corepack-enabled)"- The first line enables cli autocomplete for fnm commands
- The second line activates several configuration options that aren’t on by default:
- Use On CD: Automatically switch node versions when you
cdinto a project based on the contents of.node-versionor.nvmrc - Version File Strategy: Look in parent directories for a
.node-versionor.nvmrcfile to use - Resolve Engines: Also look in
engines.nodefield of apackage.jsonfile for a node version to use - Corepack Enabled: Automatically enable corepack on every new version of node that is installed
- Use On CD: Automatically switch node versions when you
# List available Node.js versions to installfnm list-remote
# Install a specific Node.js versionfnm install 24
# Use a specific versionfnm use 24
# Set a default versionfnm default 24
# List installed versionsfnm list