Package Manager in Node Js

In this tutorial, we are going to learn about package manager in node js. We will learn about local and global packages in detail and also discuss the main difference between them.

What is a Package Manager in Node Js?

Node Package Manager or NPM is a toolbox for downloading, installing and uninstalling node.js packages inside the node js applications. NPM can be found online as an open-source repository and this is possible because of the contributions of node js who creates problem solving modules and packet them further into packages.

Recommended Books

NPM packages can be used not only in node js but other frameworks of javascript as well such as Angular JS, Vue Js etc. You can download the NPM packages for your projects from here:

Node Package Manager


Node Package Manager comes built-in within the installation of node.js. You can verify the presence of NPM on your machine by writing commands on terminal or command prompt:

User-MacBook-Air:~ User$ npm -v

You can update the current version of NPM if you are using an old version by using the command below:

npm install npm -g

Types of Packages in Node.js

There are two types of packages in Node.js:

  1. Local Packages
  2. Global Packages

Local Packages

Local packages are installed within the directory of your project and will be only accessible for that project only. you can find the modules/packages installed in a folder named node_modules inside your current project directory. To install a package locally you can simple execute the following command on terminal or command prompt:

npm install

Global Packages

Global packages are installed in a global scope at a single time regardless where you are executing the command. The reason they are called global packages is because you can them for any of your project instead of just a specified project. To install a package globally you can simple execute the following command on terminal or command prompt:

npm install -g

Difference between Local and Global Packages

The main difference between local and global packages is that global packages can be accessed through a global scope and they can be used for any project whereas local packages work only for project specified folders where you are constructing your application.

Which One To Use?

Nodejs developers prefer using packages on a local scale and there is a very good reason to do that. Let’s say that you a lot of nodejs projects running at one time and you might want to use different packages of different versions for them then you don’t need global packages. You can only create package specific applications without worrying about globally installing or updating your packages.

And, if you do update your global packages in order to save time then your machine might crash node js applications which are already anticipating different versions of for different projects. In short, it’s not a good practice to use packages globally.