Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient. Node.js’ package ecosystem, npm, is the largest ecosystem of open source libraries in the world.

Installation using Node.js official website
One of the way installing Node.js on Mac is using the official website https://nodejs.org/ where you can download the pre compiled binary package. Click the download button and get the latest package.

Node.js Official Website

Install the package from the .pkg and follow the wizard to complete the installation of node and npm. Node Package Manger (npm) will help you install additional packages on node.

node_installer

Installation using HomeBrew
There is a better way to install node on mac using brew. Homebrew does all task of downloading, unpacking and installing node and npm on your mac.

Homebrew is a package manager for the Mac — it makes installing most open source sofware (like Node) as simple as writing brew install node. You can learn more about Homebrew at the Homebrew website.

To install Homebrew just open Terminal and type

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

homebrew_installation

Once the brew is installed, installing node and npm is very easy. Just type

brew install node

on your terminal and sit back while it downloads, unpacks and installs necessary files on your system.

Node installation using brew

Use Terminal to check if the node and npm was successfully installed on your machine.
Check node version

node -v

Check npm version

npm -v

check_version

 

Below are some of the useful npm commands

Install package

npm install <package name>

Install package locally

 npm install <package name>

Install package globally

npm install <package name> -g

Uninstall package locally

npm uninstall <package name>

Uninstall package globally

npm uninstall <package name> -g

Search a package

npm search <package name>

List local packages

npm ls

List local packages

npm ls -l

List global packages

npm ls -g

List global packages details

npm ls -gl

Update local packages

npm update

Update global packages

npm update -g