Node Package Manager -NPM

Node Package Manager or NPM is a command line tool used while working with Node.js. NPM provides the following features for Node.js developers:

  • As there are lots of packages for Node.js ,NPM makes it easier to manage them.It represents a repository of all the packages available for Node.js. We can install the packages using NPM.
  • As all the packages are present in central Node.js repository we  can search these using NPM.We can use NPM to search a particular package as :

NPM important commands

Following are useful commands for managing node.js packages

To download a package

For example following will download a package named test_package

This command will download the mentioned package to the node_modules directory.It will create node_modules directory
in the current directory if it doesn’t exist.

Using a package

We can use a package which is in the node_modules directory in our application by using the require() method.

For example we can use a module named test_package in our application as:

To install a package globally we use the following command:

global packages differs from local packages in following ways:

  • They are installed in the system directory
  • They can be used from the command line
  • They can not be used in a package using require

View the installed packages

To view the list of all locally installed modules using the following command

Above command will display the list of packages as well as the location where the packages are installed

node-js-package-ls

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *