The first step for preparing for our project is to install Node.js. There are two ways to do this:
- One option is to install the Node Version Manager (NVM). The benefit of using NVM is that you are easily able to run multiple versions of Node.js side by side and this handles the installation process for you on nearly all UNIX-based systems, such as Linux and macOS. Within this book, we do not need the option to switch between different versions of Node.js.
- The other option is to install Node.js via the package manager of your distribution if you are using Linux. The official PKG file is for Mac, whilst the MSI file is for Windows. We are going to use the regular Linux package manager for this book as it is the easiest method.
We are taking the second option above. It covers the regular server configurations and is easy to understand. I will keep this as short as possible and skip all other options, such as Chocolatey for Windows or Brew for Mac, which are very specialized for those specific operating systems.
I assume that you are using a Debian-based system for ease of use with this book. It has got the normal APT package manager and repositories to easily install Node.js and MySQL. If you are not using a Debian-based system, you can look up the matching commands to install Node.js at https://nodejs.org/en/download/package-manager/.
Our project is going to be new so that we can use Node.js 10 without any problems. You can skip the following installation of Node.js if you are running version 6 or higher:
- First, let's add the correct repository for our package manager by running:
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash –
- Next, install Node.js and the build tools for native modules, using the following command:
sudo apt-get install -y nodejs build-essential
- Finally, let's open a terminal now and verify that the installation was successful:
node --version
Great. You're now set up to run server-side JavaScript with Node.js and install Node.js modules for your projects with npm.
All of the dependencies that our project relies on are available at https://npmjs.com and can be installed with npm or Yarn, if you are comfortable with these.