Loading, please wait...

NPM (Node Package Manager)

NPM (Node Package Manager)

NPM provides online repositories for node.js packages/modules which are searchable on search nodejs.org. It also provides command line utility to install Node.js packages, do version management and dependency management of Node.js packages.

NPM is included with Node.js installation. After you install Node.js, verify NPM installation by writing the following command in terminal or command prompt.

npm --v  OR  npm –version

This is running on a terminal as shown

Rest Api Project is my Project name and my NPM version is 6.4.1

Running on command prompt

An older version of NPM then can update it to the latest version using the following command.

NPM performs the operation in two modes, global and local.

  • Global mode: NPM performs operations which affect all the Node.js applications on the computer
  • Local mode: NPM performs operations for the particular local directory which affects an application in that directory only.
  1. Install package Locally Use the following command to install any third party module in your local Node.js project folder.

       Then install express: npm install express

 

  • json is present in the root directory of any Node application/module and is used to define the properties of a package. Your package.json file should look like the code shown below.

 

Explanation:

  • Name− the name of the package
  • Version− of the package
  • Description− of the package
  • Author− author of the package
  • Dependencies− list of dependencies. NPM automatically installs all the dependencies mentioned here in the node_module folder of the package.
  • Repository− type and URL of the package
  • Main− entry point of the package
  1. Install-Package Globally

NPM can also install packages globally so that all the node.js application on that computer can import and use the installed packages.

Updating of Package

To update the package installed locally in your Node.js project, navigate the command prompt or terminal window path to the project folder and write the following update command.

Uninstall-Package

The following command will uninstall express from the application.