Node.js and Version Managers
Learn how to install and use Node.js version managers, including NVM and FNM.
AI-powered write-up, verify yourself!
This is one of those things, most developers (including me) just install and use without thinking about it. So, just doing quick-AI write-up to learn it.
What is Node.js?
Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. It allows you to run JavaScript on your computer (outside of a web browser) and is commonly used for building web servers, APIs, command-line tools, and desktop applications.
Why do I need a Node.js version manager?
Different projects often require different versions of Node.js. Some older projects might need Node.js 14, while newer ones might require Node.js 18 or 20. A version manager lets you:
- Install multiple Node.js versions on the same machine
- Switch between versions easily for different projects
- Avoid conflicts between project requirements
- Keep your global Node.js installation clean
What are NVM and FNM?
NVM (Node Version Manager) - The original and most popular Node.js version manager
- Written in bash
- Works on macOS, Linux, and Windows (via WSL)
- Mature and well-documented
FNM (Fast Node Manager) - A faster, modern alternative to NVM
- Written in Rust
- Significantly faster than NVM
- Cross-platform (macOS, Linux, Windows)
- Simpler codebase
Installing NVM
macOS/Linux
Windows
Use nvm-windows - download the installer from the GitHub releases page.
Installing FNM
macOS (via Homebrew)
Linux/macOS (via curl)
Windows (via Chocolatey)
Windows (via Scoop)
Basic NVM Commands
Basic FNM Commands
Setting Up Shell Integration
NVM
Add to your ~/.bashrc
or ~/.zshrc
:
FNM
Add to your ~/.bashrc
or ~/.zshrc
:
Automatic Version Switching
Both NVM and FNM can automatically switch Node.js versions when you enter a project directory.
Using .nvmrc files
Create a .nvmrc
file in your project root:
Then:
- NVM: Run
nvm use
in the project directory - FNM: Will automatically switch if you have
--use-on-cd
enabled
Using package.json
FNM can also read the engines
field in package.json
:
Which should I choose: NVM or FNM?
Choose NVM if:
- You want the most mature and widely-used option
- You need extensive documentation and community support
- You're working in a team that already uses NVM
- You need features specific to NVM
Choose FNM if:
- You want faster performance (especially on Windows)
- You prefer modern tooling
- You want automatic version switching via
.nvmrc
files - You're starting fresh and want the most efficient option
Common Workflows
Setting up a new project
Switching between projects
Troubleshooting
Command not found after installation
- Make sure you've reloaded your shell:
source ~/.bashrc
orsource ~/.zshrc
- Check if the installation added the necessary lines to your shell configuration
- Try opening a new terminal window
NVM is slow on Windows
- Consider using FNM instead, which is significantly faster on Windows
- Or use nvm-windows, which is specifically designed for Windows
npm packages not found after switching versions
- Each Node.js version has its own global npm packages
- You'll need to reinstall global packages for each version
- Consider using
npx
instead of global installs when possible
Version not switching automatically
- Make sure you have shell integration set up correctly
- For FNM, ensure you have the
--use-on-cd
flag in your shell configuration - Check that you have a
.nvmrc
file in your project root
Best Practices
General
- Use
.nvmrc
files in your projects to specify Node.js versions - Keep your version manager updated
- Use LTS (Long Term Support) versions for production projects
- Document the required Node.js version in your project's README
Team Collaboration
- Commit
.nvmrc
files to version control - Include Node.js version requirements in your project documentation
- Consider using
engines
field inpackage.json
Performance
- Don't install too many versions you don't need
- Use FNM if you need better performance, especially on Windows
- Consider using
npx
instead of global package installations
Migrating from NVM to FNM
- Note your installed versions:
nvm list
- Install FNM
- Install needed Node.js versions with FNM
- Update your shell configuration to use FNM
- Optionally remove NVM:
rm -rf ~/.nvm
Alternative Version Managers
- n - Simple Node.js version manager (macOS/Linux only)
- volta - JavaScript tool manager (handles Node.js, npm, yarn)
- asdf - Version manager for multiple languages (with Node.js plugin)
Getting Help
- NVM: GitHub repository
- FNM: GitHub repository
- Check the respective documentation for detailed guides
- Use
nvm --help
orfnm --help
for command-specific help
Last updated on