Home >>Nodejs Tutorial >Node.js Package Manager(NPM)
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
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.
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.
You may use npm ls command to list down all the locally available modules.
Open the Node.js command prompt and execute "npm ls":
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
First line here tells the version of the module and its location where it is being installed.
Use the following command, to uninstall a Node.js module:
npm uninstall express
You can verify by using the following commandthe Node.js module is uninstalled:
npm ls
Now, you can see the module is empty.
The command "npm search express" is used for express search or module searches.
npm search express