Installing and configuring Node.js
We'll need to install Node.js after installing the MySQL database management system because it's necessary for executing our server code.
We have several options for installing Node.js on our operating system:
- Node Version Manager (NVM), which you can use to run various versions of Node.js on your development system, acquire information about the available versions, and install any version with a single command
- The operating system's official package manager, such as APT for Ubuntu, Homebrew for macOS, or Chocolatey for Windows
- The binaries from the official website at https://nodejs.org/en/download/, which not only provides Windows, macOS, and Linux binaries, but also source code that can be downloaded and compiled
As previously said, we will presume you are running a Debian-based system such as Ubuntu. In this chapter, we'll teach you how to use the first method on an Ubuntu system.
Important Note
If you are not using an Ubuntu or Debian-based system, go to the official website at https://nodejs.org/en/download/package-manager/ and get the necessary instructions to install Node.js on your operating system.
Installing Node.js with nvm
You can install Node.js and npm using nvm instead of your system's native package manager. This utility does not operate at the system level. Instead, it makes use of a distinct folder in your home directory.
This allows you to install several versions of Node.js at the same time and quickly switch between them as needed. In addition, after you've installed nvm, you can quickly install any version of Node.js, old or new, with a single command.
Let's go over the steps:
- Return to your command-line interface and run the following command to download the nvm installation script:
curl -sL https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh
- Then, use the following command to execute the script:
bash install.sh
This command will clone the nvm repository under the ~/.nvm
folder and update the ~/.profile
file as necessary.
- To begin utilizing nvm, just source the following file or log out and then log back in:
source ~/.profile
- Using this command, you can quickly retrieve a list of available Node.js versions that you can install:
nvm ls-remote
- We are using
v12.22.1
in this book, which you can install using the following command:nvm install v12.22.1
This will download the installation binary that is compatible with your operating system and install Node.js together with npm. It will also make this version the default version.
- To verify the installed version, use the following command:
node –v
In our case, we get v12.22.1
printed on the Terminal.
More information on the available commands and how to use them may be found in the official repository at https://github.com/nvm-sh/nvm.
The nvm utility is compatible with Linux, macOS, and Windows Subsystem for Linux (WSL). You may use two unofficial alternatives for Windows:
- nvm-windows, which may be found at https://github.com/coreybutler/nvm-windows
- nodist, which may be found at https://github.com/marcelklehr/nodist
That's everything – you've configured your development machine to run Node.js, allowing you to install and use Node.js packages such as Express.js to build your backend application, as well as frontend libraries and tools such as Angular CLI.
We'll use npm to install the dependencies for our backend and frontend apps throughout this book.