We can install Node.js a few different ways. Either approach should suffice for this class.
Approach 1: Installing Node.js with a GUI Installer
The first approach to install Node.js is from the Node.js site with a GUI installer. Choose the Long Term Support (LTS) version, which is the green button on the left.
The only issue you may run into (Mac users in particular) when installing Node.js this way is when you install Node.js modules globally. For example, if you run npm install -g create-react-app
, you may get an error saying something along the lines of not having sufficient privileges. In order to get around this, you can prefix that command with sudo
(e.g. sudo npm install -g create-react-app
). Another issue with installing Node.js like this is if you have multiple projects that use different Node.js versions. We will use a single version of Node.js for everything we do in this class, but if you have other projects that depend on a specific version of Node, this is something to be aware of and you may want to consider Approach 2 below.
Approach 2: Installing Node.js with Node Version Manager (NVM)
A more popular approach to installing Node.js is through Node Version Manager (NVM) for Mac or Node.js version manager for Windows. NVM allows you to have multiple versions of Node.js installed on your computer at once. You also don't run into the problem of having to use sudo
when installing modules globally.
Unfortunately I don't have a Windows machine nor have I used NVM on Windows before. I did however see lots of tutorials on YouTube. If you're on a Mac and wish to install Node.js via NVM, follow these instructions:
- Follow the instructions under "Install & Update Script": https://github.com/nvm-sh/nvm#install--update-script.
- Restart Terminal
- Type
nvm
and press Enter. You should see a list of options. - To install version 14.17.3 of Node.js, run
nvm install v14.17.3
. Replace "v14.17.3" with any recent version. Any version greater than or equal to 14.0.0 should suffice for this course. Once that finishes, runnvm ls
to list out all the versions of Node.js that you have installed. If you would like to set a specific version of Node.js as the default, runnvm alias default <version>
(e.g.nvm alias default v14.17.3
).
To verify you have Node.js installed, open up your command line and run node -v
. You should see the version of Node.js that you installed.