What is Node, NPM and why do I want to use it?
Node is a Javascript Runtime built for backend applications, which allows you to write programs using Javascript that wouldn’t run within a website but within a computer or operating system.
NPM stands for Node Package Manager, which comes bundled with Node, to allow you to install prebuilt libraries (called packages) that others have built to allow you to develop your application faster. You can use NPM to install these packages into the application you are working on (via npm install <PACKAGE_NAME>
) or to install packages to add functionality to your own computer (using the global flag, npm install -g <PACKAGE_NAME>
)
You would want to use these technologies if you want to write applications in Javascript and run or test them on your computer.
A quick note, this is a guide to help someone without a lot of software development experience with how to install Node. The following article contains generalizations on how the technology works and makes decisions to use tools that are very approachable but may not be the right tools to use for more advanced users. Please keep that in mind.
Now, let’s get starting on how to install them!
Step 0: Install a package manager for your OS
A package manager is a bit of software that allows you to manage installed applications using the CLI (Command-Line Interface) and make it super easy to install, update, and remove applications using the computer terminal. Typically, you would only find package managers with Linux systems, but we will be leveraging some community-built options for Mac and Windows to have the same benefit.
We will be installing a package manager first, and then use it to install Node and NPM. If you already use Homebrew or Chocolatey, you can skip this step.
Word of warning as you follow any of these steps and continue to use Package Managers in the future. While I’ve done diligence with the links I am providing at the time of writing, I’m unable to certainly state that the information I provide is safe. You will need to investigate that these links are still accurate and verify on your own to ensure that what you are installing is safe for your computer.
Developing with MacOS? — Use Homebrew
Homebrew makes it super simple to install software typically used for development into your Apple computer. Follow the instructions on the Homebrew homepage to use the terminal to install the package manager.
The entire process takes place within the Terminal application. Once installed, you will be able to install software managed by Homebrew with the following command within Terminal:
brew install <PACKAGE_NAME>
Developing with Windows?— Use Chocolatey
You can install Chocolatey using the steps they provide on the Chocolatey Installation Docs, which will instruct you to install using Windows Powershell in Administrator mode.
Once installed, you can use Windows PowerShell to install, update, and uninstall software managed by the Chocolatey community.
choco install <PACKAGE_NAME>
Other/Advance Usage
Are you using Linux? Or do you have the need to switch between different versions of Node and NPM? If so, I recommend installing NVM (Node Version Manager) for Linux, MacOS, and Windows WSL (Windows Sub-system Linux) directly. This tool can be installed into Linux systems and gives you greater control over switching between versions of Node.
Step 1: Use your OS Package Manager to install Node.js and NPM
NPM is a part of Node, so we can locate the community packages for Node (also known as Node.js or Node JS) and simply install the one package to use both tools.
MacOS — Install Node via Homebrew
This is the community package for Node with Homebrew, which can be installed with the following command:
brew install node
Windows — Install Node via Chocolatey
This is the community package for Node with Chocolatey, which can be installed with the following command:
choco install nodejs
Step 2: Verify the installation was successful
Once the script in Step 1 is completed, exit out of your Terminal/PowerShell window and reopen the program. This is important to ensure that Terminal/PowerShell will have an updated list of packages that can accept commands.
Once it is reopened, run the following command:
node --version
and
npm --version
After running each command, Node and NPM should print out their current version if install successfully.
Troubleshooting
I receive an error that I do not have permissions to install.
If you’re running into an issue with permission, try rerunning the commands with Administrator privledges.
MacOS
Add sudo
before the installation command, a common Linux command prefix that will run a command as administrator. This may prompt you to enter in the computer password to verify you have admin privileges.
Windows
Close and reopen PowerShell, but instead of left-clicking the program icon, right-click and select Run as Administrator.
If you still run into issues with installation, and there is someone else that maintains your computer, you may need them to run these commands on your behalf.