Open In App

Describe the mechanism of NPM

Improve
Improve
Like Article
Like
Save
Share
Report

NPM stands for Node Package Manager that is used to manage various dependencies of the node.js framework. It is a command-line tool that can be used to install, update and uninstall the node.js packages in the application. It acts as a repository for all the open-sources packages of the node.js framework. Anyone can contribute to this repository in form of new features and repairing the bugs and issues that might have occurred and needs to be handled from time to time.

NPM is automatically installed with the node.js installation as a part of the install package. You can check whether NPM is installed on your system by using the following command:

npm -v

In order to check the available commands that you can perform using the NPM can be seen using the help command as follows:

npm -help

Installing dependencies using NPM:

There are two modes to install the dependencies in the system: local and global. In the global mode, the dependency is installed for all the applications present in the system and can be accessed without installing, again and again, the same dependency. The other one is the local mode, in which the dependency is installed locally to the particular local directory and available for the applications inside that directory as we will not be able to access the dependency outside of that directory.

Installing dependencies locally:

In order to install a dependency locally, we can use the install command with the <package name> which we want to install as given below:

npm install <package name>

Installing a package using NPM creates the ExpressJS folder under the node_modules in the root folder of the project and express.js will be installed inside the folder.

Installing dependencies globally:

In order to install a dependency globally, we have to use -g variable after the install command to specify that we want to install the dependency globally in the system as given below:

npm install -g <package name>

Installing a package globally creates a directory in user/local/lib/node_modules folder that is accessible to all the applications in the system and is not bound to any specific directory.

Uninstalling dependencies using NPM:

We can uninstall a dependency using the uninstall command followed by the <package name> of the dependency that we want to uninstall from the system this is not bound locally or globally and uninstalls all the instances of the dependency from the system.

npm uninstall <package name>

Updating dependencies using NPM:

If a new version of a dependency is released then it can be updated using the NPM with the help  of the update command with the <package name> as given follows:

npm update <package name>


Last Updated : 22 Oct, 2021
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads