Fast Node Management With fnm

10/14/20191 Min Read — In Reason, Node.js, DevTools

fnm offers a speedy alternative to the Node.js manager NVM.
Built with native ReasonML, it's significantly faster than NVM.

fnm Setup

Here's how I set it up on an Arch-based Linux system that uses the Fish shell as an interactive shell.

Use the installation script from fnm:

$ curl -fsSL https://github.com/Schniz/fnm/raw/master/.ci/install.sh | bash

The command downloads fnm, installs it and adds a loader to bash.
The installation script above adds the following lines to .bashrc:

export PATH="~/.fnm:PATH"
eval "`fnm env --multi`"

This won't work in fish. You can delete those lines.

But bash is only the container for the interactive fish shell.
Here's (part of my) .bashrc:

exec fish

Now set the fish user path:

$ set -U fish_user_paths ~/.fnm $fish_user_paths

Plus, add this line to the config.fish file:

fnm env --multi | source

Now, fnm is available in fish shell.

Install a node version with fnm install and alias it.

How to install globally available packages across all node versions?

My solution comes from a GitHub issue: minimize globally installed packages, put the necessary packages into a dedicated folder.

Create a folder to hold the globally installed packages, for example ~/.npmbin.

$ npm config set prefix `~/.npmbin`

Now use the normal command to install a package globally with npm install -g. The packages now land in ~/.npmbin/bin.

Add this to $PATH:

$ set -U fish_user_paths ~/.npmbin/bin $fish_user_paths