Difference between dependencies, devDependencies and peerDependencies - GeeksforGeeks (2024)

Last Updated : 10 Sep, 2024

Summarize

Comments

Improve

Dependencies are part of the project required to run the project, devDependencies are only required for the development while peerDependencies specifies the compatible versions of the packages to be used in the project.

Table of Content

  • Dependencies
  • devDependencies
  • peerDependencies
  • Difference between Dependencies, devDependencies and peerDependencies
  • Conclusion

Every web application project typically includes a file named package.json, which serves as a repository of essential project metadata. This file encompasses information ranging from dependencies and their respective versions to development dependencies and peer dependencies.

Run the following command to initialize the project from the root directory of your project:

npm init -y

Dependencies

In the 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:

package.json:

"dependencies": { 
"moment": "^2.30.1",
}

devDependencies

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

package.json:

"devDependencies": {
"bootstrap": "^5.3.2",
}

peerDependencies

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.

Difference between Dependencies, devDependencies and peerDependencies

DependenciesdevDependenciespeerDependencies
A dependency is a library that a project needs to function effectively.devDependencies are the packages a developer needs during development.A peer dependency specifies that our package is compatible with a particular version of an npm package.
If a package doesn’t already exist in the node_modules directory, then it is automatically added.As you install a package, npm will automatically install the dev dependencies.peerDependencies are not automatically installed. You need to manually modify your package.json file in order to add a Peer Dependency.
These are the libraries you need when you run your code.These dependencies may be needed at some point during the development process, but not during execution.Peer dependencies are only encountered when you publish your own package, that is, when you develop code that will be used by other programs.
Included in the final code bundle.Included in the final code bundle .Can be included only when you are publishing your own package.

Dependencies can be added to your project by running :

npm i <package_name>

Dev dependencies can be added to your project by running :

npm i <package_name> 
--save-dev
Change the package.json file manually.

Conclusion

In a web development project Dependencies are needed for production, devDependencies are for development only, and peerDependencies ensure compatibility with specific versions of other packages, often used by plugins or shared libraries.



Difference between dependencies, devDependencies and peerDependencies - GeeksforGeeks (1)

Improve

Please Login to comment...

Difference between dependencies, devDependencies and peerDependencies - GeeksforGeeks (2024)
Top Articles
SIP vs Lump Sum Investment: How to make your first Rs 1 crore in 5 years; know through expert tips
REITs vs. Stocks Comparison (2023) - The Tokenist
$4,500,000 - 645 Matanzas CT, Fort Myers Beach, FL, 33931, William Raveis Real Estate, Mortgage, and Insurance
2018 Jeep Wrangler Unlimited All New for sale - Portland, OR - craigslist
Regal Amc Near Me
Moviesda Dubbed Tamil Movies
Decaying Brackenhide Blanket
Rainfall Map Oklahoma
How Quickly Do I Lose My Bike Fitness?
Craigslist Greenville Craigslist
Spelunking The Den Wow
Ap Chem Unit 8 Progress Check Mcq
Charmeck Arrest Inquiry
Fredericksburg Free Lance Star Obituaries
Operation Cleanup Schedule Fresno Ca
ARK: Survival Evolved Valguero Map Guide: Resource Locations, Bosses, & Dinos
Iu Spring Break 2024
Lehmann's Power Equipment
Lawson Uhs
Kirksey's Mortuary - Birmingham - Alabama - Funeral Homes | Tribute Archive
Naval Academy Baseball Roster
Caring Hearts For Canines Aberdeen Nc
Sister Souljah Net Worth
Naya Padkar Gujarati News Paper
Devotion Showtimes Near Regency Buenaventura 6
Workshops - Canadian Dam Association (CDA-ACB)
Kirk Franklin Mother Debra Jones Age
Mami No 1 Ott
Valley Craigslist
Gesichtspflege & Gesichtscreme
Craigs List Jax Fl
417-990-0201
Khatrimmaza
47 Orchid Varieties: Different Types of Orchids (With Pictures)
Jay Gould co*ck
Senior Houses For Sale Near Me
T&J Agnes Theaters
Linabelfiore Of
Bay Focus
Collier Urgent Care Park Shore
More News, Rumors and Opinions Tuesday PM 7-9-2024 — Dinar Recaps
Newsweek Wordle
Energy Management and Control System Expert (f/m/d) for Battery Storage Systems | StudySmarter - Talents
Best GoMovies Alternatives
18006548818
Free Crossword Puzzles | BestCrosswords.com
Lorton Transfer Station
Phone Store On 91St Brown Deer
Abigail Cordova Murder
Used Auto Parts in Houston 77013 | LKQ Pick Your Part
Ippa 番号
Latest Posts
Article information

Author: Velia Krajcik

Last Updated:

Views: 6429

Rating: 4.3 / 5 (54 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Velia Krajcik

Birthday: 1996-07-27

Address: 520 Balistreri Mount, South Armand, OR 60528

Phone: +466880739437

Job: Future Retail Associate

Hobby: Polo, Scouting, Worldbuilding, Cosplaying, Photography, Rowing, Nordic skating

Introduction: My name is Velia Krajcik, I am a handsome, clean, lucky, gleaming, magnificent, proud, glorious person who loves writing and wants to share my knowledge and understanding with you.