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 d
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
Difference between Node.js and React.js
Node.js and React.js are two powerful technologies widely used in the development of modern web applications. While both are based on JavaScript, they serve entirely different purposes and are used at different stages of the web development process. This article provides a detailed comparison betwee
5 min read
Difference between __dirname and ./ in Node.js
Working with any technology requires to interact with files and directories. Files and directories maintain a tree structure for easy access. Working with Node.js also requires accessing files using the file path which can be obtained using different commands. There are two ways of getting the curre
3 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 process.cwd() and __dirname in Node.js
In Node.js, both process.cwd() and __dirname are used to get the directory paths, but they serve different purposes. The key difference is that process.cwd() returns the current working directory from which the Node.js process was started, while __dirname returns the directory name of the current mo
3 min read
Difference Between Node.js and Python
Node.js and Python are two of the most popular programming languages for backend development. Each has its own strengths and weaknesses, and the choice between them often depends on the specific requirements of the project. This article provides a detailed comparison of Node.js and Python, highlight
4 min read
Difference between Node.js and Ruby on Rails
Before stepping into a new project, the software developing team goes through a severe discussion in order to choose the best language, framework, or methodology for their project. As we are aware, the different technologies have their different pros and cons and similarly the technology which is lo
8 min read
What Is The Difference Between Gulp and NPM?
When it comes to modern web development, automation and package management play an important role in speeding up the development process and ensuring code consistency across projects. Two common tools in the developer's toolbox for handling tasks related to automation and dependency management are G
4 min read
Difference between spawn() and fork() methods in Node.js
Node.js provides several ways to create child processes, enabling you to run tasks in parallel and leverage multi-core systems efficiently. Two commonly used methods for this purpose are spawn() and fork(). While they might seem similar, they serve different purposes and have distinct features. This
4 min read