NodeJS - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

Node.js NPM

Node.js NPM

shape Introduction

The Node.js NPM is the package manager for the Node JavaScript platform, Node can intelligently manage the dependency conflicts and can find the modules easily using the package manager. Following are the concepts covered.
  • NPM installation
  • Installing packages locally

NPM installation

shape Description

The packages can be installed, updated or uninstalled easily using the Node package manager command line tool, the NPM is an online repository and useful for open-source packages of Node.js. Through this npm repository the modules are created as packages and published. By default NPM get installed with Node.js installation, using the below command the NPM installation can be verified. [c]$ npm --version[/c] By using the above command the NPM version get displayed as shown in the image below. In order to update the older version use the below command [c]$ npm install npm –g[/c] To get NPM help use the below command. [c]$ npm help[/c] Following are few commands used in NPM.
NPM Commands Description
npm adduser The command used to verify the user name in a particular register and the user data is saved to .npmrc file. The default register is used if not registered.
npm bin The command will pint the folder where the executables installed by npm.
npm bugs (package name) The bug command tries to speculate the feasible area of a package's bug tracker URL, and after that tries to open it utilizing the --browser config param.
npm build (package name) The command build is an plumbing command and not to call directly and to be called by using npm install or npm link.
npm cache The command is used to clean the cache folder.
npm completion The command enables the tab-completion in all npm commands.
npm config The config setting for npm can be obtained from the nprmc files, environment variables, package.json or from the command line.
npm debupe (package names) The command search and simplify the overall structure of local package tree and move the dependencies further up the tree by which multiple dependency packages can share them effectively.
npm deprecate The command will update the package register entry with a deprecation warning while installing.
npm docs The docs command tries to speculate the feasible area of a package's bug tracker URL, and after that tries to open it utilizing the --browser config param.
npm edit The command is used to open the folder containing package in the deafult editor.
npm explore The command generate a sub-shell in the directory where the specified package located.
npm help-search The command search the npm markdown doc files with the given terms and provided a list.
npm help (topic) The command supplies a topic and give the exact doc page.
npm init The command ask various question and then write a package.json.

Installing packages

shape Description

In Node package manager the operations are performed in two modes they are. The modules installed through Node Package Manager (NPM) are located in the folder node_module, the third party modules can be installed in local project folder of node.js using the following command. [c]$ npm install (package name)[/c]

Installing of package Locally

shape Description

The packages in Node.js can be installed locally and these packages are installed in the working directory. Suppose in order to install Express in the working directory and save it in the dependency list use the following command. [c]$ npm install express --save[/c] Use this command as shown in the image below. In order to install Express temporarily and don’t want to add to the dependency list remove --save from the command as shown below. [c]$ npm install express[/c] Use this command as shown in the image below.

Installation of package globally

shape Description

The packages in Node.js can be installed globally by which the application of node.js can use these packages, the packages of installed in the node_modules folder located under the working directory. While installing a package apply "–g" to the command in order to install that respective package globally as shown. [c] $ npm install –g (package name)[/c] Suppose if one want to install express globally type express in the place of package name from the above command as shown. [c] $ npm install –g express[/c]

Updating and uninstalling of packages

shape Description

Updating the packages - The locally installed packages can be updated and can be done using the following command. [c] $ npm update (package name) [/c] Suppose in order to update the existing express module use the above command by replacing the package name with express as shown. [c] $ npm update express [/c] Uninstalling the packages - The installed packages in the node.js can be uninstalled using the following command. [c] $ npm uninstall (package name) [/c] If supposed to uninstall express module package use the above command by replacing the package name with express as shown. [c] $ npm uninstall express [/c]

Summary

shape Key Points

  • The Node.js get included with NPM by default.
  • Utilizing the command line one can install, update or uninstall the Node.js packages.
  • The older version of NPM can be updated using the command line.