Difference between dependencies, devDependencies and peerDependencies - GeeksforGeeks

27 Jan, 2022
Introduction: In every web application project, we have a file called package.json. This file contains all the relevant data regarding the project i.e. metadata. Starting from all the dependencies used to all the version numbers are present in the file. In this way, they are three types of dependencies that are found in this file. They are dependencies, dev dependencies, and peer dependencies. 
Run the following command to initialize the project from the root directory of your project:
npm init -y
Dependencies: In package.json file, there is an object called dependencies and it consists of all the packages that are used in the project with its version number. So, whenever you install any library that is required in your project that library you can find it in the dependencies object. 
Syntax:  
npm install <package name>
Example: Installing the moment module for formatting the time in the project using the following command:  
npm install moment
After the module is installed, then if you navigate to the package.json file then you can find the moment with its version in the dependencies object as shown below:
Dev Dependencies: In package.json file, there is an object called as dev Dependencies and it consists of all the packages that are used in the project in its development phase and not in the production or testing environment with its version number. So, whenever you want to install any library that is required only in your development phase then you can find it in the dev Dependencies object. 
Use the below command to add more dev Dependencies in your project:
npm install <package name> --save-dev
Example: Installing the bootstrap module that we want to use in the development phase only and not in the production or testing phase for the project, use the following command:
npm install bootstrap --save-dev
After completion of the download, then if you navigate to the package.json file then you can find the bootstrap with its version in the dev Dependencies object as shown below:
Peer Dependencies: In package.json file, there is an object called as peerDependencies and it consists of all the packages that are exactly required in the project or to the person who is downloading and the version numbers should also be the same. That is the reason they were named as peerDependencies. The best example is ‘react’ which is common in every project to run similarly. 
Note: These dependencies are not automatically installed. npm gives a warning message whenever there is a peer Dependency and these are different dependencies compared to the above-discussed dependencies.
The following table summarizes the dependencies, development dependencies, and peer dependencies. 
Dependencies can be added to your project by running :
npm install <package_name>
Dev dependencies can be added to your project by running :
npm install <package_name> --save-dev
mridulmanochagfg
adnanirshad158
mdayyanfahim
riyaa7vermaa
Node.js-Misc
Picked
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Express.js express.Router() Function
JWT Authentication with Node.js
Express.js req.params Property
Mongoose Populate() Method
Difference between npm i and npm ci in Node.js
Roadmap to Become a Web Developer in 2022
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Convert a string to an integer in JavaScript