JavaScript Development Tools
This page will list some helpful tools for developing Javascript applications. Some may require elevated permissions (such as an administrative account) and/or additional system tools such as Xcode command line tools and/or Homebrew.
Table of Contents
Node Version Manager (nvm)
Node Version Manager (nvm) is a utility similar to Python’s pyenv which allows quick and easy usage of different versions of Node without the hassle of installing and keeping Node up to date using typical package managers such as Homebrew.
Installation
The Github repository for nvm has its own installation instructions along with potential solutions to installation issues. In short: assume the Xcode command line tools must be installed first, and then run the following commands:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
At the time of this writing, nvm’s current release is version 0.39.7
- be sure to check the official nvm installation instructions to get the commands for installing the current latest version.
You should not require elevated rights in order to run the above commands. After doing so, confirm that nvm has been installed properly by running the following:
nvm --version
You should see a version number corresponding to the version you just installed. Again - as of this writing, the version number you see should be 0.39.7
.
Usage
nvm allows you to install any version of Node you need and quickly swap between versions. This allows you to have multiple versions of Node available at any time, so if you’re working on two different projects that require different versions of Node you can quickly switch back and forth.
It has a great many different functions in addition to this, but for the most part they are not necessary.
Before you’ll be able to use a version of Node, you’ll have to install it. This is very easy to do. For example, suppose you’re working on a legacy project that still requires some version of Node 12 in order to build/run. You could install Node version 12 like so:
nvm install 12
Or, if you want to target the specific version of Node required by your project:
nvm install 12.20.2
You can do this to have different minor/patch versions of Node either as a requiremente for your project or to test for compatibility.
For example, suppose you’re looking to update the same project from Node version 12 to version 18. You’d just have to install the latest stable release of Node 18:
nvm install 18
But, suppose you are already working on a project using Node 18 which, for whatever reason, must use an older version of Node 18. Hypothetically, the other existing project would require Node 18.12.1. You could install that one like this:
nvm install 18.12.1
You can run nvm ls
at any time to see which versions of Node you have installed, and nvm use
to swap between them.
For example, suppose you need to work on the legacy project running Node 12:
nvm use 12
And then later, you want to work on the other project that’s locked at 18.12.1:
nvm use 18.12.1
And then after that, you want to switch to the latest release of Node 18 to work on modernizing one or the other project:
nvm use 18
Keep in mind that nvm will alias Node versions differently. When running nvm ls
you will also be able to see your configured aliases. For example:
nvm ls
# terminal output below
v6.17.1
v12.3.1
v12.11.1
v12.20.2
v14.16.1
v16.19.0
v18.12.1
v18.13.0
-> v18.16.0
system
default -> 18.16.0 (-> v18.16.0)
node -> stable (-> v18.16.0) (default)
stable -> 18.16 (-> v18.16.0) (default)
iojs -> N/A (default)
unstable -> N/A (default)
lts/* -> lts/hydrogen (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.1 (-> N/A)
lts/hydrogen -> v18.17.0 (-> N/A)
Note the ->
in the terminal output indicating which version of Node you are currently using. When you start a new terminal window or tab, nvm (assuming it was installed properly and starts automatically) will automatically use whichever version of node has been aliased as ‘default’. In the case of the above output, you can see that the default version of Node is 18.16.0.
You can set which version of Node is automatically active in new terminal tabs by changing the ‘default’ alias. For example, if you wanted new terminal windows to use v18.16.0 by default, you would run the following command:
nvm alias default 18.16.0
Now any time you start a new terminal window, you will automatically be using Node 18.16.0. Keep in mind that if you later install a more recent version of Node 18, you may have to update the ‘default’ alias to use that version instead.
Environment Management
Much like pyenv for Python, nvm sandboxes each version of Node it installs in its own sort of virtual environment. That means, basically, that whatever additional tools or global packages you install while one version of Node is active will not be available if you switch to using another instance of Node.
For example, refer back to the previous section’s different projects - suppose you’re working on the legacy project requiring Node 12 again, you would switch to the Node 12 environment like so:
nvm use 12
Suppose that you want to install the ‘yarn’ package globally in order to more easily manage Javascript dependencies for your project. Luckily, Node Package Manager (npm) is available automatically with every version of Node installed by nvm, so you’d only have to run the following:
npm install -g yarn
Now you’d be able to use yarn as desired for any project that requires Node 12. You can confirm that yarn is installed by running yarn -v
, which should output the installed version of yarn. Suppose that you then want to switch to Node 18 to start looking for any compatibility issues that need to be changed. You’d do so by running the following:
nvm use 18
Now that you’re using Node 18, you’re in a different sandboxed environment than you were before. If you run yarn -v
here, instead of a version number you should see ‘command not found: yarn’. This is because you have not yet installed yarn in the Node 18 environment. Follow the same instructions as you did when you installed it while running Node 12, and you should be all set.