Difference between npm install and npm update in Node.js
Last Updated :
25 Jan, 2021
NPM is like a powerhouse for Node.js that contains all the necessary modules for the smooth running of the node.js application. It gets installed on our machine when we install Node.js on our Windows, Linux or MAC OS.
How to install Node on the machine? Refer to this article.
NPM has 580096 registered packages. The average rate of growth of this number is 291/day that means the growth of different kind of packages increasing drastically, so we have to update our node every time on our machine ? The answer is No! NPM allows us to install third-party modules on our machine according to the need of our work.
Another reason is predefined modules cannot be able to fulfill the need for big projects for e.g. HTTP modules cannot differentiate the multiple kinds of requests, so we have to install externally another popular module. i.e express module.
We can access third party modules using some predefined commands provided by Node Package Manager are given below:
Initial Project Structure :
npm install command: This npm command is used for installing the third party modules in our current directory. There are two different ways to use this command:
- Without Parameter
- With Parameter
- Without Parameter: When we use the npm command without a parameter this command automatically downloads all the dependencies that are written in the package.json file in our directory.
Package.json: create a package.json file in the directory and mention express dependencies in this file.
{
"name": "gfg",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Run npm install command:
npm i
or
npm install
Updated Project Structure:
package-lock.json file and node_modules created package-lock.json file contains all the necessary information of downloaded extra dependencies and node_modules folder contains all the different types of packages that installed along with our specified module in the package.json.

- With Parameter: We can use the npm install command by specifying the name of the third-party module that we want to install for particular work. For e.g. let's download MongoDB module for Node.js
Parameter: Parameter can be the name of the module that we want to install or folder name in which we want to install all third-party modules in the directory. By default, the folder is node_modules that contains all the installed modules. This folder is automatically generated when we install any external module the first time.
Syntax:
npm install [-g] [<package>..]
- Syntax for installing module: Module will get install in the node_modules folder in the present directory.
npm install <module-name>
- Syntax for installing any module globally: Globally installing means we can access the module without installing that module in a particular directory. For eg Nodemon module etc.
npm install -g <module-name>
- Syntax for change the directory path of modules: This command will change the installing path of the external modules from node_modules to <dirname> folder in the working directory.
npm install <dirname>
Explanation: After installing any new module new packages are added to the node_modules folder and dependencies are updated to the package.json file.
- Installing module using npm command:
npm install mongodb
package.json file:
npm update command: This npm command is used for updating the dependencies that are mention in the package.json file as well as install all the missing packages in the directory and also used for updating the current node version on the machine.This command used in two different ways:
- Without Parameter
- With Parameter
- Without Parameter: npm update without parameter works on all globally installed packages and update all the versions of the globally packages available on our machine.
Syntax:
npm update -g
Updating nodemon module that was installed globally:

- With parameter: npm update command takes the second parameter as a dependency name that we want to update the next version or latest version. We can also restrict the updating of the dependencies to the latest version with the help of some reserved symbols. If we install dependencies simply by mention its name, the latest patch of the dependencies will get install but it might create some problem because when we're working on a project and want nearly equal to the current version dependence it. We cannot be able to come to install that particular dependency we will use reserved symbols to convert the updating track of the dependency
There are mainly types of dependencies used in Node.js:
1. Caret Dependencies: When dependencies present in the package.json or package.lock.json file with ^ called Caret Symbol is called Caret Dependencies.These dependencies are updated to the latest version compatible to that version.
"dependencies": {
"dep11": "^2.2.2"
}
This npm update command will update to 2.3.3 (consider this version exists) and 2.3.3 satisfy previous version
2.Tilde Dependencies: npm update command will update these dependencies to the highest sorted version. These dependencies use ~ symbol.
"dependencies": {
"dep11": "^2.2.2"
}
If we update this dependency, it will get updated to 2.2.3 version in this case.
Difference:
- The npm install installs all modules that are listed on package.json file and their dependencies.
- npm update updates all packages in the node_modules directory and their dependencies.
Similar Reads
Difference between npm i and npm ci in Node.js npm i or npm install is used to install, modify, and update the dependencies in a project along with updating the dependencies in package-lock.json while npm ci only reinstalls all the packages mentioned in the package-lock.json with the specified versions and can't modify the lock packages.Let's di
2 min read
Difference between React.js and Node.js 1. React.js : This is the Javascript library that was developed by Facebook in 2013. This library was developed in order to improve and enhance the UI for the web apps but with time it has evolved a lot. It is open-source and supports different inbuilt functions and modules like form module, routing
2 min read
What is the difference between StrongNode and Node.js ? StrongLoop Node is a packaged distribution of Node.js, NPM, and the slc. The slc is a command-line utility and a set of supported npm modules that comes with StrongLoop Node for building and managing applications. Some tools and modules that come with the StrongLoop Node are Express, Connect, Passpo
2 min read
Difference between Node.js and JavaScript JavaScript and Node.js are both crucial in modern web development, but they serve different purposes and are used in different environments. JavaScript is a programming language primarily used for client-side web development, while Node is a runtime environment that allows JavaScript to be executed
3 min read
Difference Between --save and --save-dev in NodeJS In NodeJS, when you install packages using npm (Node Package Manager), you often need to decide whether to install them as a dependency or devDependency. This is where the flags --save and --save-dev come into play. These flags control where the installed packages are placed in the package.json file
5 min read