Home >>Nodejs Tutorial >Node.js Package Manager(NPM)

Node.js Package Manager(NPM)

Node.js Package Manager

There are two functionalities are provided by Node Package Manager:

It provides do version management, dependency management of Node.js packages and command line utility to install Node.js packages.

It also provides node.js modules/packages of online repositories which are searchable on search.nodejs.org.

In versions after v0.6.3, the npm comes bundled with Node.js installables. The iteration can be tested by opening the Node.js command prompt and typing the code:

npm  version 

Node Js Package

Installing Modules using npm

The syntax below for install any Node.js module is:

npm install <Module Name>

Let's install a popular Web framework called Node.js Express:

open the command prompt Node.js and execute the following command:

npm install express

After intalling the "express" framework, you can see the impact.

Node Js Package

Global vs Local Installation

By default npm installs local mode dependence. Local mode here defines the folder where application Node is present. For instance, if you installed an express module, it generated node modules directory in the current directory where the express module was installed.

Node Js Package

You may use npm ls command to list down all the locally available modules.

Open the Node.js command prompt and execute "npm ls":

Node Js Package

Packages / dependencies installed globally are stored in the system directory. Using global installation let's install Express module. Though it will also produce the same result, it will also install modules globally.

Open the command prompt Node.js and execute the code below:

npm install express -g

Node Js Package

First line here tells the version of the module and its location where it is being installed.

Uninstalling a Module

Use the following command, to uninstall a Node.js module:

npm uninstall express

Node Js Package

You can verify by using the following commandthe Node.js module is uninstalled:

npm ls

Node Js Package

Now, you can see the module is empty.

Searching a Module

The command "npm search express" is used for express search or module searches.

npm search express

Node Js Package

Node Js Package