Introduction
NodeJS is a runtime environment for JavaScript. It allows developers to create applications that run on the backend of your computer or sever, rather than in the browser.
There are many uses for NodeJS, but for front end developers the most important are:
- Managing development dependencies such as
sass
,eslint
,tsc
orprettier
. - Managing front end dependencies such as
bootstrap
,tailwind
orreact
. - Previewing changes with a live development server.
- Running tests on front end components.
Key Terms
Node
: The runtime environment for JavaScript.Dependency
: A package that is required to run a project.Package
: A collection of files that can be installed as a dependency.NPM
: Node Package Manager used to install/upgrade/remove dependencies.NPX
: Node Package Execute used to run packages that are not installed.
Installing NodeJS with NVM
Before you can use NodeJS, it must be installed in one of two ways. You can either install a specific version of NodeJS to your computer or you can install a Node Version Manager
(NVM) tool in order to manage multiple versions of NodeJS.
Different versions of NodeJS offer different tools and features. Some packages will only run with a specific NodeJS version and will require you to switch your installation in order to use them. It is therefore recommended to use a Version Manager
, although this adds more steps to the process.
Please make sure that you do not have an existing installation of NodeJS on your computer before attempting to install NVM. If you have installed NodeJS before, you should uninstall it first.
Installing on Unix (MacOS, Linux)
Run either the curl
or wget
command to install depending on which is available to you:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash
Close and reopen your terminal and check that the installation was successful by using the command:
nvm --version
Installing on Windows
The best way to manage packages such as nvm
on Windows is to install the Windows Subsystem for Linux (WSL) and follow the Unix installation instructions. WSL allows for Unix commands to be used inside Windows, something that will be useful throughout the course.
You can read more about WSL here: Windows Subsystem for Linux
There is also a package called nvm-windows
which serves as a parallel project to nvm
for Windows users who cannot use WSL. You can read about that project here: nvm-windows.
Installing NodeJS with NVM
Once NVM is correctly installed on your computer, you can use the command nvm ls
to list all of the available versions. From these versions, select the version you would like to use (or use the latest lts
release if you are not sure):
nvm ls
default -> lts/* (-> v16.16.0)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v16.16.0) (default)
stable -> 16.16 (-> v16.16.0) (default)
lts/* -> lts/gallium (-> v16.16.0)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.20.0 (-> N/A)
lts/gallium -> v16.16.0
From this list, the latest stable release would be lts/gallium
which can be installed like so:
nvm install lts/gallium
Switching NodeJS Versions with NVM
If you already have another version installed and would like to switch to another installed version, you can use this command:
nvm use <version>
Installing NodeJS
Although it is recommended to use NVM in order to manage your NodeJS installation, this tutorial will cover the process of installing NodeJS directly onto your computer without a Version Manager
.
All installation files can be found on the NodeJS website: NodeJS Downloads
NVM
NVM is the recommended way to install and manage NodeJS Versions on your computer.
You can find the tutorial for installing Node with NVM here: Installing Node with NVM.
MacOS
Start by downloading the Mac installer for the correct version of Node you require from the link above.
The installer package will walk you through the process. When the installation process has finished, check that it worked correctly by running the command:
node -v
This should output the version of NodeJS that you have installed.
Linux
The easiest way to install NodeJS on Linux is to use the built in package manager for your distribution. For example, users with apt
would install NodeJS using the following command:
sudo apt install nodejs
You can also install using the downloadable package from the link above.
Once installed, check that it worked correctly by running the command:
node -v
This should output the version of NodeJS that you have installed.
Windows
Start by downloading the Windows installer for the correct version of Node you require from the link above.
The installer package will walk you through the process. When the installation process has finished, check that it worked correctly by running the command:
node -v
This should output the version of NodeJS that you have installed.