What is NPM ?
Note: Dependencies are the packages that are used in our projects and part of the package.json.
NPM comes with Node.js and is pre-installed with Node. Package.json is the file containing the details of your project such as who created it, and what is the version of node and packages that your project is dependent on.
A package is basically a set of files combined together to serve a specific interest of function. If we visit then we can search for different packages based on the functionality we need. For example, if you search for ‘date format’ to support multiple locales, we get 1171 packages (as on the date this article was written) with the topmost package being ‘moment’.
In short, if you are thinking of a functionality to build, then there is a high chance that there is a package already available in NPM for the same. As of January 2021, the current count is 1,493,231 packages.
NPM is used for building lightweight projects that can be easily shared across multiple development teams without dependencies being shared. It allows free use of resources and installs the dependencies only when needed.
Node/npm can be installed on Mac, Windows or Linux as well. Let’s go through the steps involved in installing it on Mac. The approach should be similar for the other Operating systems.
For Linux, refer to this.
Navigate to and you will see the download section. Under the download, there is the other downloads link which will display different operating systems. Download the one specific to your Operating System.
Double click on the node-v**.**.*.pkg to install the node. It is a simple wizard with straightforward steps.
npm is installed with Node.js
If you are wondering why we are installing node instead of NPM, this is because Node.js installs NPM along with it. This is evident from the below snapshot.
How to check that you have node and npm installed
The most common way to check if node or npm is installed is by looking at the terminal.
Open terminal and Type in `node -v` and you should see the same version display in the installation wizard. The same applies to npm; i.e. You can type in ‘npm -v’ in terminal.
On Versions - A note on versions, npm versions, Node versions and Long-Term Support
When we are downloading the node.js from, we have two options; i.e. LTS and Current, both pointing to different versions, and currently on the higher version.
LTS stands for ‘long time support’ and Current is the version that has the latest features, and offers support for 6 months. After 6 months, odd-numbered releases will become unsupported and even numbered ones will be given LTS status with support for 30 months.
So, for all production applications, one should rely on Active LTS or Maintenance LTS releases. Current can be used for any trainings or by source contributors i.e. library authors.
Use a Node.js version manager
Imagine you are working on an Enterprise application for an organization which uses a specific version of Node LTS. Also imagine that there is another app (it could be your pet project) that you are working on, for which you prefer to work on the latest version. But how can we have two different versions of Node in the same machine?
To achieve the same, we have NVM (Node.js version manager). Here is the official site for Mac and Linux users. Windows users can visit this link.
Follow the installation steps to install the NVM on your machine.
To verify if NVM is installed correctly, open the terminal and type in ‘nvm --version.’
Type in ‘nvm list’ to display all the node.js versions that are installed on your machine. For now, you should be seeing only one version.
Say you want to install an outdated version of Node.js, say 12. Type in ‘nvm install 12’ in terminal and it should install the 12 version of Node.js for you.
Now, type in ‘nvm list’ to see both the versions of node that are available for use.
To switch to a specific version of node, type in ‘nvm use 12’. To check if it is the active one, type in ‘node -v’.
Now you are good to go ahead with your project for that specific version of node.js.
NPM is one of the world's largest software registries. The Source contributors or developers are from across the world, and use npm to share or use packages. Many organizations/firms use npm for private development as well. NPM has 3 components i.e. Website, Command Line Interface and Registry.