Node Package Manager (NPM) is an essential tool for managing dependencies in Node.js projects. It allows developers to install, update, and uninstall packages easily. This article will guide you through the process of uninstalling and updating dependencies using NPM.
Node Package Manager (NPM) is the primary package manager for Node.js. It is automatically installed when you install Node.js. When you use the npm client on the command line to install a package in your project, the package is installed in the node_modules folder, and information such as the package version is recorded in the package.json file.
We have different approaches to manage the dependencies according to the requirement as mentioned below:
Table of Content
For Project Dependencies
We can update the project dependencies using the update command:
npm updateWe can update any particular project dependency using the following command:
npm update <packagename>We can uninstall a project dependency using the following command:
npm uninstall <package_name>For Global Dependencies
We can update the global dependencies using the update command with the -g flag.
npm update -gWe can update any particular global dependency using the following command:
npm update -g <package_name>We can uninstall a global dependency using the following command:
npm uninstall -g <package_name>Steps to Setup Project
Step 1: Make a folder structure for the project.
mkdir myappStep 2: Navigate to the project directory
cd myappStep 3: Initialize the NodeJs project inside the myapp folder.
npm init -yProject Structure:

Note: Now to begin with the example we will install an old version of two packages named express and chalk using the following command on the command line.
npm install express@4.15.4 chalk@2.3.1The updated dependencies in package.json file will look like:
"dependencies": {
"chalk": "^2.3.1",
"express": "^4.15.4",
}
To see the outdated packages for your project you can run the following command.
npm outdatedWhen using the outdated command we get the following output. In the output, the first column is the name of the package and the second column shows the version installed for our project. The third column represents the wanted version that is the version to which we can safely upgrade without any breaking changes. The fourth column represents the latest version of that package.

Now, when we use the npm update command then both the packages are updated to the latest safe versions and we get the following output. As the wanted and the latest version of the express were the same, it got updated to the latest version. The only outdated dependency we are left with is chalk.

For Uninstalling

The updated dependencies in package.json file will look like:
"dependencies": {
"express": "^4.19.2",
}