How to install NodeJs on Mac

Best way to install NodeJs is using NVM (Node Version Manager)

Installing NVM

Check bash_profile file exist

[ -f ~/.bash_profile ] && echo "File exist" || echo "File does not exist"

Apple has announced that in macOS 10.15 Catalina the default shell will be zsh. Therefore you have to rename your configuration files. .bashrc is now .zshrc and .bash_profile is now .zprofile.

The main change you will see is that the prompt character.

  • zsh uses the % character as the default prompt
  • bash uses the $ character as the default prompt

Basic syntax/commands

  • see all available shells in macOS Catalina => cat /etc/shells
  • to change to bash shell, run and relaunch Terminal => chsh -s /bin/bash
  • to change to bash shell, run and relaunch Terminal => chsh -s /bin/zsh


To install nvm run script, do:

curl -o- | bash

To verify that nvm has been installed, do:

command -v nvm

Some useful commands

% nvm list                      # list all installed node versions
% nvm install node              # "node" is an alias for the latest version
% nvm ls-remote                 # list available versions online

% nvm use node
% nvm run node --version
% nvm exec 4.2 node --version   # run any arbitrary command in a subshell with the desired version of node:

% nvm which current

% nvm current
% nvm -v

Install MacPorts

MacPorts initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac operating system. To Install MacPorts for your version of the Mac operating system, go to and select macOS Catalina v10.15

After installation run below command to check for the proper installation if MacPorts on your mac

sudo port selfupdate

Install Yarn using MacPorts

sudo port install yarn
yarn --version

Some information about Yarn installation

yarn stores data in:


By default, these packages will be installed in ~/.config/yarn/global, and soft-linked to /opt/local/bin. 

To uninstall them all:

ls -1 $HOME/.config/yarn/global/node_modules/  | xargs sudo yarn > global remove

You may then remove the directories listed above and uninstall yarn. yarn is meant to replace NPM and may cause conflicts if you use both. You may override the default global installation directory by setting > the PREFIX environment variable, e.g.

mkdir -p $HOME/.config/yarn/bin # Or wherever you want
export PREFIX=$HOME/.config/yarn/bin

Top npm modules

npm i http-server
npm i fs-extra
npm i moment
npm i async
npm i underscore underscore.string
npm i validator
npm i csv           # npm i csv-generate csv-parse stream-transform csv-stringify
npm i axios
npm i objection     # An SQL-friendly ORM for Node.js
npm i typescript