In the web development industry, Node.js is a household name. This is because it powers everything from video streaming on Netflix to helping astronauts stay safe in space.
When it comes to installing Node.js on a development machine, you would normally install the environment using these steps:
You might think to yourself, “Sure, this process works for me.” However, there is a minor flaw in this process: it is too tedious and time-consuming. This is because of the following reasons:
This is where fnm
comes in. It is a piece of software written in Rust that allows developers to switch between Node versions with relative ease.
In this article, you will learn about the fnm
project. Here is what we’ll cover:
fnm
, and why you should use it?fnm
fnm
fnm
fnm, or Fast Node Manager, is a Node version manager that was written in Rust. Since it is a version manager, it boasts the easy installation of different Node.js versions. You can install Node via the install
command:
Other than that, uninstalling is a breeze. For example, we can remove different Node versions using the uninstall
command:
fnm uninstall <version> #uninstall a version of Node.js fnm uninstall 19.3.0 #use this version of Node.js
Moreover, this project is written in Rust. This means that fnm
brings speed and stability to the table.
The fnm
team bundles an installation script that makes downloading the software a breeze. To run this script, type this command in your terminal:
curl -fsSL https://fnm.vercel.app/install | bash
Don’t want to use the terminal? No problem! Head over to the Releases page and install their binaries.
When that’s done, verify that everything works by writing this bash command:
fnm --help
This should return this result:
This means that our installation was successful! In the next section, we will now learn how to install Node.js using fnm
.
To download and install specific versions of Node.js, use the following syntax:
fnm install <version>
For example, this command installs 14.15.0
on the dev machine:
fnm install 14.15.0
Alternatively, if you want to use the latest version, simply use the --latest
flag, like so:
fnm install --latest
This will be the result:
Otherwise, to install the lts
version, just pass the --lts
argument:
fnm
to list all Node versions that are available to download:fnm ls-remote
If you want to see what versions are installed on the system, just write:
fnm list
As you can see, in my case, two Node.js versions (18
and 19
) were installed on the local machine.
To use a specific version of Node, we have to run the use
command. It follows this syntax:
fnm use <version>
For example, if you want your computer to switch to Node 19.3.0
:
fnm use 19.3.0
We can verify that we’ve changed our version with the current
command:
fnm current
This indicates that our machine is now running Node version 19.3.0
.
To purge certain Node installations, use the uninstall
keyword like so:
fnm uninstall <version>
For example, this removes Node 19.3.0
:
fnm uninstall 19.3.0 #uninstall the latest version of node
Aliases allow developers to “name” certain Node versions semantically. This is a great feature because it means that programmers don’t need to remember multiple Node versions if they’re working on many projects.
To set an alias, use this syntax:
fnm alias <version> <name>
For example,
fnm alias 18.12.1 my-project
The above command assigns the my-project
alias to Node version 18.12.1
.
To verify whether our alias was successfully configured, we can re-run fnm list
:
In some cases, developers might encounter bugs, such as command issues during development. As a result, you may have to reinstall the fnm
tool to fix this. In this section, you will learn how to delete fnm
from your machine.
To purge fnm, we have to first find its installation directory:
fnm env #get all environment variables
Here, the FNM_DIR
variable indicates the location of fnm
. As the next step, go to the path and simply remove the fnm
folder like so:
#in this case, fnm was in the 'share' folder cd $HOME/.local/share rm -rf fnm #removing this folder will uninstall this software
And we’re done!
NVM (Node version manager) is an alternative to fnm
that allows developers to install and manage their Node installs. Some sample commands include:
nvm use 18.15.0 #use a certain Node version nvm install --lts #install Node to local machine
When compared to fnm
, you might notice that it is far slower. Furthermore, this application doesn’t support Windows operating systems. As a workaround, The nvm team recommends nvm-windows, but it is not officially supported.
Similar to nvm, Volta is also a Node version management tool. Just like fnm
, it was also built with Rust, thus bringing stability and speed to the table. Moreover, it lets creators “pin” certain Node engines. This means that if there’s a project that relies on a certain Node install, Volta will automatically switch to that Node version to prevent instability issues in the stack.
volta install node # install latest Node LTS volta pin node@14 # tell Volta that our project will use this node version
Since its launch, Fast Node Manager has become the default way to install Node on my computer. Although other alternatives like nvm and Volta exist, fnm
has always been my tool of choice because of its speed and simplicity.
Thank you so much for reading! Happy coding!
Deploying a Node-based web app or website is the easy part. Making sure your Node instance continues to serve resources to your app is where things get tougher. If you’re interested in ensuring requests to the backend or third-party services are successful, try LogRocket.
LogRocket is like a DVR for web and mobile apps, recording literally everything that happens while a user interacts with your app. Instead of guessing why problems happen, you can aggregate and report on problematic network requests to quickly understand the root cause.
LogRocket instruments your app to record baseline performance timings such as page load time, time to first byte, slow network requests, and also logs Redux, NgRx, and Vuex actions/state. Start monitoring for free.
Would you be interested in joining LogRocket's developer community?
Join LogRocket’s Content Advisory Board. You’ll help inform the type of content we create and get access to exclusive meetups, social accreditation, and swag.
Sign up nowNitro.js is a solution in the server-side JavaScript landscape that offers features like universal deployment, auto-imports, and file-based routing.
Ding! You got a notification, but does it cause a little bump of dopamine or a slow drag of cortisol? […]
A guide for using JWT authentication to prevent basic security issues while understanding the shortcomings of JWTs.
Auth.js makes adding authentication to web apps easier and more secure. Let’s discuss why you should use it in your projects.