Node and NPM

2020-04-20T00:00:00.000Z

Arthur Chu

package manager

Overview

Node.js allows your Mac to run JavaScript on the server side. Without node.js JavaScript will only run on the client side inside a browser like Google Chrome or Firefox.

NPM (Node Package Manager) allows us to download Node Packages, these packages range from build tools, utilities, frameworks, libraries, etc...

Installing NVM

Check if Node is Installed.

node --version

A Version Number should be printed in the Terminal if you have it installed

If not, we will install NVM(Node Version Manager). Note: Installing with Homebrew causes issues sometimes.

Run the Following Command and hit return.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

Once the install is complete Close Terminal

Open a new window.

Run the following command

command -v nvm

If everything worked then you can skip down to Installing Node section.

If you got an error we need to manually add something to your terminal profile. First we need to determine if you're running bash or zsh

echo $0

For bash - .bash_profile

echo '#nvm command"' >> ~/.bash_profile
echo 'export NVM_DIR="$HOME/.nvm"' >> ~/.bash_profile
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm' >> ~/.bash_profile
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion' >> ~/.bash_profile

For zsh - .zshrc

echo '#nvm"' >>  ~/.zshrc
echo 'export NVM_DIR="$HOME/.nvm"' >>  ~/.zshrc
echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm' >>  ~/.zshrc
echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion' >>  ~/.zshrc

Close Terminal

Reopen a new termian window.

Run the following command

command -v nvm

Check your nvm version

nvm --version

Installing Node

We can now install node with nvm. The following command will install the latest version of node.

nvm install node

tell nvm to use which version of node.

nvm use node

Check node and npm versions

node -v
npm -v

Conclusion

We didn't install node using homebrew we wouldn't be able to install multiple version of done if you require it in the future. Installing with nvm allows us to install several version and the ability to choose which version to run.

Related Guides

Get the latest up to date guys from Me.

Where I do my experimentalAHHHRT

Go